@1inch/solidity-utils 1.2.2 → 1.2.7

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.
@@ -1,90 +0,0 @@
1
- const { expect } = require('chai');
2
-
3
- const StringUtilTest = artifacts.require('StringUtilTest');
4
-
5
- describe('StringUtil', async () => {
6
- const uint256TestValue = '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF';
7
- const uint128TestValue = '0x00000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF';
8
- const veryLongArray = '0xffffffffffffffafafafbcbcbcbcbdeded' + 'aa'.repeat(50);
9
- const extremelyLongArray = '0x' + '0f'.repeat(1000);
10
- const emptyBytes = '0x';
11
- const singleByte = '0xaf';
12
-
13
- before(async () => {
14
- this.stringUtilTest = await StringUtilTest.new();
15
- });
16
-
17
- describe('Validity', async () => {
18
- it('Uint 256', () => test(uint256TestValue));
19
-
20
- it('Uint 128', () => test(uint128TestValue));
21
-
22
- it('Very long byte array', () => testBytes(veryLongArray));
23
-
24
- it('Extremely long byte array', () => testBytes(extremelyLongArray));
25
-
26
- it.skip('Empty bytes. Skipped until resolved: https://github.com/ChainSafe/web3.js/issues/4512', () => testBytes(emptyBytes));
27
-
28
- it('Single byte', () => testBytes(singleByte));
29
-
30
- const test = async (value) => {
31
- const result = await this.stringUtilTest.toHex(value, 0);
32
- const naiveResult = await this.stringUtilTest.toHexNaive(value, 0);
33
- expect(result.toLowerCase()).to.be.equal(value.toLowerCase());
34
- expect(result.toLowerCase()).to.be.equal(naiveResult.toLowerCase());
35
- };
36
-
37
- const testBytes = async (value) => {
38
- const result = await this.stringUtilTest.toHexBytes(value, 0);
39
- const naiveResult = await this.stringUtilTest.toHexNaiveBytes(value, 0);
40
- expect(result.toLowerCase()).to.be.equal(value.toLowerCase());
41
- expect(result.toLowerCase()).to.be.equal(naiveResult.toLowerCase());
42
- };
43
- });
44
-
45
- describe('Gas usage @skip-on-coverage', async () => {
46
- it('Uint 256', () => testGasUint256(uint256TestValue, 917));
47
-
48
- it('Uint 256 naive', () => testGasNaiveUint256(uint256TestValue, 14175));
49
-
50
- it('Uint 256 as bytes', () => testGasBytes(uint256TestValue, 792));
51
-
52
- it('Uint 256 as bytes naive', () => testGasNaiveBytes(uint256TestValue, 14050));
53
-
54
- it('Uint 128', () => testGasUint256(uint128TestValue, 917));
55
-
56
- it('Uint 128 naive', () => testGasNaiveUint256(uint128TestValue, 14175));
57
-
58
- it('Very long byte array gas', () => testGasBytes(veryLongArray, 1974));
59
-
60
- it('Very long byte array gas naive', () => testGasNaiveBytes(veryLongArray, 28972));
61
-
62
- it('Extremely long byte array gas', () => testGasBytes(extremelyLongArray, 19131));
63
-
64
- it('Extremely long byte array gas naive', () => testGasNaiveBytes(extremelyLongArray, 426795));
65
-
66
- it('Empty bytes', () => testGasBytes(emptyBytes, 201));
67
-
68
- it('Empty bytes naive', () => testGasNaiveBytes(emptyBytes, 406));
69
-
70
- it('Single byte', () => testGasBytes(singleByte, 792));
71
-
72
- it('Single byte naive', () => testGasNaiveBytes(singleByte, 832));
73
-
74
- const testGasUint256 = async (value, expectedGas) => {
75
- await this.stringUtilTest.toHex(value, expectedGas);
76
- };
77
-
78
- const testGasBytes = async (value, expectedGas) => {
79
- await this.stringUtilTest.toHexBytes(value, expectedGas);
80
- };
81
-
82
- const testGasNaiveUint256 = async (value, expectedGas) => {
83
- await this.stringUtilTest.toHexNaive(value, expectedGas);
84
- };
85
-
86
- const testGasNaiveBytes = async (value, expectedGas) => {
87
- await this.stringUtilTest.toHexNaiveBytes(value, expectedGas);
88
- };
89
- });
90
- });
@@ -1,45 +0,0 @@
1
- const { expect } = require('chai');
2
- const { profileEVM, gasspectEVM } = require('../js/profileEVM.js');
3
- const { ether } = require('@openzeppelin/test-helpers');
4
-
5
- const TokenMock = artifacts.require('TokenMock');
6
-
7
- contract('', function ([wallet1, wallet2]) {
8
- before(async function () {
9
- this.USDT = await TokenMock.new('USDT', 'USDT');
10
- });
11
-
12
- beforeEach(async function () {
13
- for (const addr of [wallet1, wallet2]) {
14
- await this.USDT.mint(addr, ether('1000'));
15
- }
16
- });
17
-
18
- describe('profileEVM', async function () {
19
- it('should be counted ERC20 Transfer', async function () {
20
- const receipt = await this.USDT.transfer(wallet2, ether('1'), { from: wallet1 });
21
- expect(await profileEVM(receipt.tx, ['STATICCALL', 'CALL', 'SSTORE', 'SLOAD']))
22
- .to.be.deep.equal([0, 0, 2, 2]);
23
- });
24
-
25
- it('should be counted ERC20 Approve', async function () {
26
- const receipt = await this.USDT.approve(wallet2, ether('1'), { from: wallet1 });
27
- expect(await profileEVM(receipt.tx, ['STATICCALL', 'CALL', 'SSTORE', 'SLOAD']))
28
- .to.be.deep.equal([0, 0, 1, 0]);
29
- });
30
- });
31
-
32
- describe('gasspectEVM', async function () {
33
- it('should be counted ERC20 Transfer', async function () {
34
- const receipt = await this.USDT.transfer(wallet2, ether('1'), { from: wallet1 });
35
- expect(await gasspectEVM(receipt.tx))
36
- .to.be.deep.equal(['0-0-SLOAD = 2100', '0-0-SSTORE = 2900', '0-0-SLOAD = 2100', '0-0-SSTORE = 2900', '0-0-LOG3 = 1756']);
37
- });
38
-
39
- it('should be counted ERC20 Approve', async function () {
40
- const receipt = await this.USDT.approve(wallet2, ether('1'), { from: wallet1 });
41
- expect(await gasspectEVM(receipt.tx))
42
- .to.be.deep.equal(['0-0-SSTORE = 2200', '0-0-LOG3 = 1756']);
43
- });
44
- });
45
- });
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
- });