-
Notifications
You must be signed in to change notification settings - Fork 77
/
zsc.js
126 lines (115 loc) · 4.41 KB
/
zsc.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const CashToken = artifacts.require("CashToken");
const ZSC = artifacts.require("ZSC");
const Client = require('../../anonymous.js/src/client.js');
contract("ZSC", async (accounts) => {
let alice; // will reuse...
let bob;
let carol;
let dave;
let miner;
it("should allow minting and approving", async () => {
const cash = await CashToken.deployed();
const zsc = await ZSC.deployed();
await cash.mint(accounts[0], 1000);
await cash.approve(zsc.contract._address, 1000);
const balance = await cash.balanceOf.call(accounts[0]);
assert.equal(
balance,
1000,
"Minting failed"
);
});
it("should allow initialization", async () => {
const zsc = await ZSC.deployed();
alice = new Client(web3, zsc.contract, accounts[0]);
await alice.register();
});
it("should allow funding", async () => {
await alice.deposit(100);
});
it("should allow withdrawing", async () => {
await alice.withdraw(10);
});
it("should allow transferring (2 decoys and miner)", async () => {
const zsc = await ZSC.deployed();
bob = new Client(web3, zsc.contract, accounts[0]);
carol = new Client(web3, zsc.contract, accounts[0]);
dave = new Client(web3, zsc.contract, accounts[0]);
miner = new Client(web3, zsc.contract, accounts[0]);
await Promise.all([bob.register(), carol.register(), dave.register(), miner.register()]);
alice.friends.add("Bob", bob.account.public());
alice.friends.add("Carol", carol.account.public());
alice.friends.add("Dave", dave.account.public());
alice.friends.add("Miner", miner.account.public());
await alice.transfer("Bob", 10, ["Carol", "Dave"], "Miner");
await new Promise((resolve) => setTimeout(resolve, 100));
assert.equal(
bob.account.balance(),
10,
"Transfer failed"
);
const fee = await zsc.fee.call();
assert.equal(
miner.account.balance(),
fee,
"Fees failed"
);
});
it("should allow transferring (2 decoys and NO miner)", async () => {
const zsc = await ZSC.deployed();
await alice.transfer("Bob", 10, ["Carol", "Dave"]);
await new Promise((resolve) => setTimeout(resolve, 100));
assert.equal(
bob.account.balance(),
20,
"Transfer failed"
);
});
it("should allow transferring (6 decoys and miner)", async () => {
const zsc = await ZSC.deployed();
bob1 = new Client(web3, zsc.contract, accounts[0]);
carol1 = new Client(web3, zsc.contract, accounts[0]);
dave1 = new Client(web3, zsc.contract, accounts[0]);
miner1 = new Client(web3, zsc.contract, accounts[0]);
await Promise.all([bob1.register(), carol1.register(), dave1.register(), miner1.register()]);
alice.friends.add("Bob1", bob1.account.public());
alice.friends.add("Carol1", carol1.account.public());
alice.friends.add("Dave1", dave1.account.public());
alice.friends.add("Miner1", miner1.account.public());
await alice.transfer("Bob", 10, ["Carol", "Dave", "Bob1", "Carol1", "Dave1", "Miner1"], "Miner");
await new Promise((resolve) => setTimeout(resolve, 100));
assert.equal(
bob.account.balance(),
30,
"Transfer failed"
);
const fee = await zsc.fee.call();
assert.equal(
miner.account.balance(),
fee,
"Fees failed"
);
});
it("should allow transferring without decoys or miner", async () => {
const zsc = await ZSC.deployed();
zuza = new Client(web3, zsc.contract, accounts[0]);
await zuza.register()
alice.friends.add("Zuza", zuza.account.public());
await alice.transfer("Zuza", 5);
await new Promise((resolve) => setTimeout(resolve, 100));
assert.equal(
zuza.account.balance(),
5,
"Transfer failed"
);
});
it("should allow transferring without decoys but with miner", async () => {
await alice.transfer("Carol", 5, [], "Miner");
await new Promise((resolve) => setTimeout(resolve, 100));
assert.equal(
carol.account.balance(),
5,
"Transfer failed"
);
});
});