-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwallet.js
180 lines (128 loc) · 5.06 KB
/
wallet.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
const erc20 = artifacts.require('erc20');
const erc721 = artifacts.require('erc721');
const erc777 = artifacts.require('erc777');
const walletAbstraction = artifacts.require('wallet');
let wallet, walletOwner;
contract('wallet', accounts => {
beforeEach(async () => {
wallet = await walletAbstraction.new({ from: accounts[0] });
walletOwner = accounts[0];
});
it('...should accept eth deposit.', async () => {
const sender = accounts[0];
const wallet_starting_balance = await web3.eth.getBalance(wallet.address);
const amount = web3.utils.toWei('1', 'ether');
await web3.eth.sendTransaction({
from: sender,
to: wallet.address,
value: amount
});
const wallet_ending_balance = await web3.eth.getBalance(wallet.address);
assert.equal(
wallet_starting_balance,
wallet_ending_balance - amount,
'ETH was not correctly deposited.'
);
});
it('...should send eth.', async () => {
const sender = accounts[0];
const receiver = accounts[1];
const amount = web3.utils.toWei('1', 'ether');
await web3.eth.sendTransaction({
from: sender,
to: wallet.address,
value: amount
});
const wallet_starting_balance = await web3.eth.getBalance(wallet.address);
const receiver_starting_balance = await web3.eth.getBalance(receiver);
await wallet.sendETH(receiver, amount, { from: walletOwner, gas: 40000 });
const wallet_ending_balance = await web3.eth.getBalance(wallet.address);
const receiver_ending_balance = await web3.eth.getBalance(receiver);
assert.equal(
wallet_starting_balance - amount,
wallet_ending_balance,
'ETH was not correctly sent.'
);
assert.equal(
receiver_starting_balance,
receiver_ending_balance - amount,
'ETH was not correctly sent.'
);
});
it('...should accept erc20 tokens deposit.', async () => {
const sender = accounts[0];
const erc20Token = await erc20.deployed();
const wallet_starting_balance = await erc20Token.balanceOf.call(wallet.address);
const amount = 100;
await erc20Token.transfer(wallet.address, amount, { from: sender });
const wallet_ending_balance = await erc20Token.balanceOf.call(wallet.address);
assert.equal(
wallet_starting_balance,
wallet_ending_balance - amount,
'ERC20 tokens were not correctly deposited.'
);
});
it('...should send erc20 tokens.', async () => {
const receiver = accounts[1];
const amount = 100;
const erc20Token = await erc20.deployed();
await erc20Token.transfer(wallet.address, amount, { from: accounts[0] });
let receiver_starting_balance = await erc20Token.balanceOf.call(receiver);
await wallet.sendERC20(erc20Token.address, receiver, amount, { from: walletOwner, gas: 4000000 });
balance = await erc20Token.balanceOf.call(receiver);
const receiver_ending_balance = balance.toString();
assert.equal(
receiver_starting_balance,
receiver_ending_balance - amount,
'ERC20 tokens were not correctly credited.'
);
});
it('...should accept erc721 token deposit.', async () => {
const sender = accounts[0];
const erc721Token = await erc721.deployed();
const mintReturnData = await erc721Token.mint();
const tokenId = mintReturnData.logs[0].args['1'].toString();
let balance = await erc721Token.balanceOf.call(wallet.address);
const wallet_starting_balance = balance.toString();
await erc721Token.transferFrom(sender, wallet.address, tokenId, { from: sender });
balance = await erc721Token.balanceOf.call(wallet.address);
const wallet_ending_balance = balance.toString();
const ownerOfNFT = await erc721Token.ownerOf.call(tokenId);
assert.equal(
wallet_starting_balance,
wallet_ending_balance - 1,
'ERC721 token was not correctly deposited'
);
assert.equal(
wallet.address,
ownerOfNFT,
'ERC721 token was not correctly deposited.'
);
});
it('...should accept erc777 tokens deposit.', async () => {
const amount = 80;
const erc777Token = await erc777.deployed();
const wallet_starting_balance = await erc777Token.balanceOf.call(wallet.address);
await erc777Token.mint(wallet.address, amount);
const wallet_ending_balance = await erc777Token.balanceOf.call(wallet.address);
assert.equal(
wallet_starting_balance,
wallet_ending_balance - amount,
'ERC777 token was not correctly deposited.'
);
});
it('...should send erc777 tokens.', async () => {
const receiver = accounts[1];
const amount = 120;
const erc777Token = await erc777.deployed();
await erc777Token.mint(wallet.address, amount);
const wallet_starting_balance = await erc777Token.balanceOf.call(wallet.address);
await wallet.sendERC777(erc777Token.address, receiver, amount, { from: walletOwner, gas: 3000000 });
const wallet_ending_balance = await erc777Token.balanceOf.call(wallet.address);
assert.equal(
wallet_starting_balance - amount,
wallet_ending_balance,
'ERC777 token was not correctly sent.'
);
});
});