Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | const { Tx, Input, Outpoint } = require('leap-core');
const checkPeriodVote = require('./checkPeriodVote');
const ADDR_1 = '0xB8205608d54cb81f44F263bE086027D8610F3C94';
const ADDR_2 = '0xD56F7dFCd2BaFfBC1d885F0266b21C7F2912020c';
const PRIV_1 =
'0x9b63fe8147edb8d251a6a66fd18c0ed73873da9fff3f08ea202e1c0a8ead7311';
const PRIV_2 =
'0xea3a59a673a9f7e74ad65e92ee04c2330fc5b905d0fa47bb2ae36c0b94af61cd';
const TENDER_KEY_1 = '0x7640D69D9EDB21592CBDF4CC49956EA53E59656FC2D8BBD1AE3F427BF67D47FA'.toLowerCase();
const TENDER_KEY_2 = '0x0000069D9EDB21592CBDF4CC49956EA53E59656FC2D8BBD1AE3F427BF67D47FA'.toLowerCase();
const merkleRoot = '0x3342fc20b1a6b66a964d58e4f56ec38c3421964237b41853a603e1abd0b7885d';
const getInitialState = () => ({
periodVotes: {},
slots: [
{
id: 0,
tenderKey: TENDER_KEY_1,
signerAddr: ADDR_1,
eventsCount: 1,
},
{
id: 1,
tenderKey: TENDER_KEY_2,
signerAddr: ADDR_2,
eventsCount: 1,
},
],
});
describe('checkPeriodVote', () => {
test('successful tx', () => {
const state = getInitialState();
const periodVoteTx = Tx
.periodVote(1, new Input(new Outpoint(merkleRoot, 0)))
.signAll(PRIV_1);
checkPeriodVote(state, periodVoteTx);
expect(state.periodVotes.keys().length).toEqual(1);
expect(state.periodVotes[1]).toBe(merkleRoot);
});
test('reject: wrong type', () => {
const tx = Tx.transfer([], []);
expect(() => checkPeriodVote({}, tx)).toThrow('[period vote] periodVote tx expected');
});
test('reject: slot is not taken', () => {
const state = getInitialState();
const periodVoteTx = Tx.periodVote(2, new Input(new Outpoint(merkleRoot, 0)));
expect(() =>
checkPeriodVote(state, periodVoteTx)
).toThrow('[period vote] Slot 2 is empty');
});
test('reject: no inputs', () => {
const state = getInitialState();
const periodVoteTx = Tx.periodVote(1, []);
expect(() =>
checkPeriodVote(state, periodVoteTx)
).toThrow('[period vote] Malformed period vote tx. Should have one input');
});
test('reject: unsigned input', () => {
const state = getInitialState();
const periodVoteTx = Tx.periodVote(1, new Input(new Outpoint(merkleRoot, 0)));
expect(() =>
checkPeriodVote(state, periodVoteTx)
).toThrow('[period vote] Input should be signed by validator');
});
});
|