From 09b2b3b013b6a35f307d7aee848f66f7e95d3a68 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 6 Jan 2019 23:13:59 -0800 Subject: [PATCH] Add tests scenario for straightforward event --- test/T6Simple.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/test/T6Simple.js b/test/T6Simple.js index 2159f81..3ef7b00 100644 --- a/test/T6Simple.js +++ b/test/T6Simple.js @@ -51,4 +51,93 @@ contract("Simple Straight forward transaction", async (accounts) => { console.log('Initial Balance:', fw(currentBal, 'ether')); }); + + it('Can Control authentication rate', async () => { + + await registry.setMaxPending(0, {from: owner} ); + + }); + + it('Can Register victim', async () => { + + await registry.authCallback(victimId, ransom.address, escrow.address, true, {from: oracle} ); + + let cnt = await registry.victimCount(); + + assert.equal(cnt, 1); + + }); + + it('Can retrieve ransom addr for victim', async () => { + + let rv_ransom = await registry.getRansomAddressForVictim(0x5500); + assert.equal(rv_ransom, ransom.address); + + }); + + it('Registry knows escrow addr for victim', async() => { + + let rv_escrow = await registry.getEscrowAddressForVictim(0x5500); + assert.equal(rv_escrow, escrow.address); + + }); + + it('Ransom knows escrow addr', async() => { + + let rv_escrow = await ransom.getEscrowAddress(); + assert.equal(rv_escrow, escrow.address); + + }); + + it('At this point ransom should be authenticated', async() => { + let rv_auth = await ransom.isAuthenticated(); + assert.isTrue(rv_auth); + }); + + it('Remember the balance' , async () => { + + ttlBalBefore = tbn(await gb(owner)).add(tbn(await gb(victim))); + console.log('Balance before :', fw(ttlBalBefore, 'ether')); + + }); + + it('After ransom is payed contract should be fulfilled', async() => { + + await escrow.payRansom(victimId, "DFDFFFD", + {from: victim, value: ransomAmount}); + + await escrow.decryptCallback(victimId, '0x01020304', true, {from: oracle} ); + + let rv_filled = await ransom.isFulFilled(); + assert.isTrue(rv_filled); + }); + + it('Victim can retrieve key from fullfilled contract', async() => { + + let key = await ransom.getDecryptionKey({from: victim }); + + assert.equal(key, '0x0102030400000000000000000000000000000000000000000000000000000000') + + }); + + it('Owner can claim funds', async() => { + + let ownerIntialBalance = await web3.eth.getBalance(owner); + + let rv = await escrow.withdrawFunds( owner, ransomAmount, {from: owner}); + console.log(rv.tx); + + let ttlBalAfter = tbn(await gb(owner)).add(tbn(await gb(victim))); + console.log('Balance after :', fw(ttlBalAfter, 'ether')); + + + let ttlBalDiff = ttlBalBefore.sub(ttlBalAfter); + console.log("Sum bal diff :", fw(ttlBalDiff, 'ether')); + + assert.isBelow(parseFloat(fw(ttlBalDiff)), 0.01); + + }); + + + }); \ No newline at end of file