Skip to content

Commit 09b2b3b

Browse files
committed
Add tests scenario for straightforward event
1 parent ce66a6b commit 09b2b3b

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

test/T6Simple.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,93 @@ contract("Simple Straight forward transaction", async (accounts) => {
5151
console.log('Initial Balance:', fw(currentBal, 'ether'));
5252

5353
});
54+
55+
it('Can Control authentication rate', async () => {
56+
57+
await registry.setMaxPending(0, {from: owner} );
58+
59+
});
60+
61+
it('Can Register victim', async () => {
62+
63+
await registry.authCallback(victimId, ransom.address, escrow.address, true, {from: oracle} );
64+
65+
let cnt = await registry.victimCount();
66+
67+
assert.equal(cnt, 1);
68+
69+
});
70+
71+
it('Can retrieve ransom addr for victim', async () => {
72+
73+
let rv_ransom = await registry.getRansomAddressForVictim(0x5500);
74+
assert.equal(rv_ransom, ransom.address);
75+
76+
});
77+
78+
it('Registry knows escrow addr for victim', async() => {
79+
80+
let rv_escrow = await registry.getEscrowAddressForVictim(0x5500);
81+
assert.equal(rv_escrow, escrow.address);
82+
83+
});
84+
85+
it('Ransom knows escrow addr', async() => {
86+
87+
let rv_escrow = await ransom.getEscrowAddress();
88+
assert.equal(rv_escrow, escrow.address);
89+
90+
});
91+
92+
it('At this point ransom should be authenticated', async() => {
93+
let rv_auth = await ransom.isAuthenticated();
94+
assert.isTrue(rv_auth);
95+
});
96+
97+
it('Remember the balance' , async () => {
98+
99+
ttlBalBefore = tbn(await gb(owner)).add(tbn(await gb(victim)));
100+
console.log('Balance before :', fw(ttlBalBefore, 'ether'));
101+
102+
});
103+
104+
it('After ransom is payed contract should be fulfilled', async() => {
105+
106+
await escrow.payRansom(victimId, "DFDFFFD",
107+
{from: victim, value: ransomAmount});
108+
109+
await escrow.decryptCallback(victimId, '0x01020304', true, {from: oracle} );
110+
111+
let rv_filled = await ransom.isFulFilled();
112+
assert.isTrue(rv_filled);
113+
});
114+
115+
it('Victim can retrieve key from fullfilled contract', async() => {
116+
117+
let key = await ransom.getDecryptionKey({from: victim });
118+
119+
assert.equal(key, '0x0102030400000000000000000000000000000000000000000000000000000000')
120+
121+
});
122+
123+
it('Owner can claim funds', async() => {
124+
125+
let ownerIntialBalance = await web3.eth.getBalance(owner);
126+
127+
let rv = await escrow.withdrawFunds( owner, ransomAmount, {from: owner});
128+
console.log(rv.tx);
129+
130+
let ttlBalAfter = tbn(await gb(owner)).add(tbn(await gb(victim)));
131+
console.log('Balance after :', fw(ttlBalAfter, 'ether'));
132+
133+
134+
let ttlBalDiff = ttlBalBefore.sub(ttlBalAfter);
135+
console.log("Sum bal diff :", fw(ttlBalDiff, 'ether'));
136+
137+
assert.isBelow(parseFloat(fw(ttlBalDiff)), 0.01);
138+
139+
});
140+
141+
142+
54143
});

0 commit comments

Comments
 (0)