Skip to content
Permalink
Browse files

Add tests scenario for straightforward event

  • Loading branch information...
vladistan committed Jan 7, 2019
1 parent ce66a6b commit 09b2b3b013b6a35f307d7aee848f66f7e95d3a68
Showing with 89 additions and 0 deletions.
  1. +89 −0 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);

});



});

0 comments on commit 09b2b3b

Please sign in to comment.
You can’t perform that action at this time.