@1inch/solidity-utils 1.2.1 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/utils.js DELETED
@@ -1,166 +0,0 @@
1
- const { expect } = require('chai');
2
- const { time, ether, BN } = require('@openzeppelin/test-helpers');
3
- const {
4
- timeIncreaseTo,
5
- fixSignature,
6
- signMessage,
7
- trackReceivedTokenAndTx,
8
- trackReceivedToken,
9
- countInstructions,
10
- } = require('../js/utils.js');
11
-
12
- const TokenMock = artifacts.require('TokenMock');
13
-
14
- describe('timeIncreaseTo', async function () {
15
- const precision = 2;
16
-
17
- async function shouldIncrease (secs) {
18
- const timeBefore = await time.latest();
19
- await timeIncreaseTo(timeBefore.addn(secs));
20
- const timeAfter = await time.latest();
21
-
22
- expect(timeAfter).to.be.bignumber.gt(timeBefore);
23
- expect(timeAfter.sub(timeBefore)).to.be.bignumber.lte(new BN(secs).addn(precision));
24
- expect(timeAfter.sub(timeBefore)).to.be.bignumber.gte(new BN(secs));
25
- }
26
-
27
- it('should be increased on 1000 sec', async function () {
28
- await shouldIncrease(1000);
29
- });
30
-
31
- it('should be increased on 2000 sec', async function () {
32
- await shouldIncrease(2000);
33
- });
34
-
35
- it('should be increased on 1000000 sec', async function () {
36
- await shouldIncrease(1000000);
37
- });
38
-
39
- it('should be thrown with increase time to a moment in the past', async function () {
40
- try {
41
- await shouldIncrease(-1000);
42
- } catch (e) {
43
- expect(e.message).contains('Cannot increase current time');
44
- expect(e.message).contains('to a moment in the past');
45
- return;
46
- }
47
- expect(true).equal(false);
48
- });
49
- });
50
-
51
- describe('fixSignature', async function () {
52
- it('should not be fixed geth sign', async function () {
53
- const signature = '0xb453386b73ba5608314e9b4c7890a4bd12cc24c2c7bdf5f87778960ff85c56a8520dabdbea357fc561120dd2625bd8a904f35bdb4b153cf706b6ff25bb0d898d1c';
54
- expect(signature).equal(fixSignature(signature));
55
- });
56
-
57
- it('should be fixed ganache sign', async function () {
58
- const signature = '0x511fafdf71306ff89a063a76b52656c18e9a7d80d19e564c90f0126f732696bb673cde46003aad0ccb6dab2ca91ae38b82170824b0725883875194b273f709b901';
59
- const v = parseInt(signature.slice(130, 132), 16) + 27;
60
- const vHex = v.toString(16);
61
- expect(signature.slice(0, 130) + vHex).equal(fixSignature(signature));
62
- });
63
- });
64
-
65
- contract('', function ([wallet1, wallet2]) {
66
- before(async function () {
67
- this.USDT = await TokenMock.new('USDT', 'USDT');
68
- this.USDC = await TokenMock.new('USDC', 'USDC');
69
- });
70
-
71
- beforeEach(async function () {
72
- for (const addr of [wallet1, wallet2]) {
73
- for (const token of [this.USDT, this.USDC]) {
74
- await token.mint(addr, ether('1000'));
75
- }
76
- }
77
- });
78
-
79
- describe('signMessage', async function () {
80
- it('should be signed test1', async function () {
81
- expect(await web3.eth.sign('0x', wallet1)).equal(await signMessage(wallet1));
82
- });
83
-
84
- it('should be signed test2', async function () {
85
- const message = web3.utils.randomHex(32);
86
- expect(await web3.eth.sign(message, wallet1)).equal(await signMessage(wallet1, message));
87
- });
88
-
89
- it('should be signed test3', async function () {
90
- const message = web3.utils.toHex('Test message'); ;
91
- expect(await web3.eth.sign(message, wallet1)).equal(await signMessage(wallet1, message));
92
- });
93
- });
94
-
95
- describe('trackReceivedTokenAndTx', async function () {
96
- it('should be tracked ERC20 Transfer', async function () {
97
- const [received, tx] = await trackReceivedTokenAndTx(
98
- this.USDT,
99
- wallet2,
100
- () => this.USDT.transfer(wallet2, ether('1'), { from: wallet1 }),
101
- );
102
- expect(received).to.be.bignumber.equal(ether('1'));
103
- expect(tx.tx.length).equal(66);
104
- expect(tx.receipt.from).equal(wallet1.toLowerCase());
105
- expect(tx.receipt.to).equal(this.USDT.address.toLowerCase());
106
- expect(tx.logs.length).equal(1);
107
- expect(tx.logs[0].event).equal('Transfer');
108
- });
109
-
110
- it('should be tracked ERC20 Approve', async function () {
111
- const [received, tx] = await trackReceivedTokenAndTx(
112
- this.USDT,
113
- wallet2,
114
- () => this.USDT.approve(wallet2, ether('1'), { from: wallet1 }),
115
- );
116
- expect(received).to.be.bignumber.equal('0');
117
- expect(tx.tx.length).equal(66);
118
- expect(tx.receipt.from).equal(wallet1.toLowerCase());
119
- expect(tx.receipt.to).equal(this.USDT.address.toLowerCase());
120
- expect(tx.logs.length).equal(1);
121
- expect(tx.logs[0].event).equal('Approval');
122
- });
123
- });
124
-
125
- describe('trackReceivedToken', async function () {
126
- it('should be tracked ERC20 Transfer', async function () {
127
- const received = await trackReceivedToken(
128
- this.USDT,
129
- wallet2,
130
- () => this.USDT.transfer(wallet2, ether('1'), { from: wallet1 }),
131
- );
132
- expect(received).to.be.bignumber.equal(ether('1'));
133
- });
134
-
135
- it('should be tracked ERC20 Approve', async function () {
136
- const received = await trackReceivedToken(
137
- this.USDT,
138
- wallet2,
139
- () => this.USDT.approve(wallet2, ether('1'), { from: wallet1 }),
140
- );
141
- expect(received).to.be.bignumber.equal('0');
142
- });
143
- });
144
-
145
- describe('countInstructions', async function () {
146
- it('should be counted ERC20 Transfer', async function () {
147
- const [, tx] = await trackReceivedTokenAndTx(
148
- this.USDT,
149
- wallet2,
150
- () => this.USDT.transfer(wallet2, ether('1'), { from: wallet1 }),
151
- );
152
- expect(await countInstructions(tx.receipt.transactionHash, ['STATICCALL', 'CALL', 'SSTORE', 'SLOAD']))
153
- .to.be.deep.equal([0, 0, 2, 2]);
154
- });
155
-
156
- it('should be counted ERC20 Approve', async function () {
157
- const [, tx] = await trackReceivedTokenAndTx(
158
- this.USDT,
159
- wallet2,
160
- () => this.USDT.approve(wallet2, ether('1'), { from: wallet1 }),
161
- );
162
- expect(await countInstructions(tx.receipt.transactionHash, ['STATICCALL', 'CALL', 'SSTORE', 'SLOAD']))
163
- .to.be.deep.equal([0, 0, 1, 0]);
164
- });
165
- });
166
- });