@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,85 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
4
- pragma abicoder v1;
5
-
6
- import "../libraries/RevertReasonParser.sol";
7
-
8
- contract RevertReasonParserTest {
9
- function emptyRevert() external pure {
10
- revert(); // solhint-disable-line reason-string
11
- }
12
-
13
- function emptyStringRevert() external pure {
14
- revert("");
15
- }
16
-
17
- function nonEmptyRevert() external pure {
18
- revert("reason");
19
- }
20
-
21
- function assertion() external pure {
22
- assert(false);
23
- }
24
-
25
- function longStringRevert() external pure {
26
- // solhint-disable-next-line reason-string
27
- revert("Very long text to test for reverts that return string of more than 32 bytes length");
28
- }
29
-
30
- function withoutAssertion() external pure {
31
- assert(true);
32
- }
33
-
34
- function testEmptyRevert() external view {
35
- _test(this.emptyRevert, "Unknown(0x)");
36
- }
37
-
38
- function testEmptyStringRevert() external view {
39
- _test(this.emptyStringRevert, "Error()");
40
- }
41
-
42
- function testNonEmptyRevert() external view {
43
- _test(this.nonEmptyRevert, "Error(reason)");
44
- }
45
-
46
- function testAssertion() external view {
47
- _test(this.assertion, "Panic(0x0000000000000000000000000000000000000000000000000000000000000001)");
48
- }
49
-
50
- function testLongStringRevert() external view {
51
- _test(this.longStringRevert, "Error(Very long text to test for reverts that return string of more than 32 bytes length)");
52
- }
53
-
54
- function testParseWithThrow() external view {
55
- try this.nonEmptyRevert() { // solhint-disable-line no-empty-blocks
56
- } catch (bytes memory reason) {
57
- bytes32 invalidReasonPart1;
58
- bytes32 invalidReasonPart2;
59
- bytes32 invalidReasonPart3;
60
- assembly { // solhint-disable-line no-inline-assembly
61
- invalidReasonPart1 := mload(add(reason, 0x20))
62
- invalidReasonPart2 := mload(add(reason, 0x40))
63
- invalidReasonPart3 := mload(add(reason, 0x40))
64
- }
65
- bytes memory invalidReason = abi.encodePacked(invalidReasonPart1, invalidReasonPart2, invalidReasonPart3);
66
- RevertReasonParser.parse(invalidReason, "");
67
- }
68
- }
69
-
70
- function testWithThrow() external view {
71
- _test(this.withoutAssertion, "Error(reason)");
72
- }
73
-
74
- function _test(function() external pure testFunction, string memory expectedReason) private pure {
75
- try testFunction() {
76
- revert("testFunctions without throw");
77
- } catch (bytes memory reason) {
78
- string memory parsedReason = RevertReasonParser.parse(reason, "");
79
- require(
80
- keccak256(abi.encodePacked(expectedReason)) == keccak256(abi.encodePacked(parsedReason)),
81
- string(abi.encodePacked("Expected { ", expectedReason, " }, but got { ", parsedReason, " }"))
82
- );
83
- }
84
- }
85
- }
@@ -1,26 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.0;
4
- pragma abicoder v1;
5
-
6
- import "../libraries/StringUtil.sol";
7
- import "../mocks/libraries/StringUtilNaive.sol";
8
- import "../GasChecker.sol";
9
-
10
- contract StringUtilTest is GasChecker {
11
- function toHex(uint256 value, uint256 expectedGasCost) external view checkGasCost(expectedGasCost) returns (string memory) {
12
- return StringUtil.toHex(value);
13
- }
14
-
15
- function toHexBytes(bytes memory data, uint256 expectedGasCost) external view checkGasCost(expectedGasCost) returns (string memory) {
16
- return StringUtil.toHex(data);
17
- }
18
-
19
- function toHexNaive(uint256 value, uint256 expectedGasCost) external view checkGasCost(expectedGasCost) returns (string memory) {
20
- return StringUtilNaive.toHex(value);
21
- }
22
-
23
- function toHexNaiveBytes(bytes memory data, uint256 expectedGasCost) external view checkGasCost(expectedGasCost) returns (string memory) {
24
- return StringUtilNaive.toHex(data);
25
- }
26
- }
package/hardhat.config.js DELETED
@@ -1,33 +0,0 @@
1
- require('@nomiclabs/hardhat-etherscan');
2
- require('@nomiclabs/hardhat-truffle5');
3
- require('dotenv').config();
4
- require('hardhat-deploy');
5
- require('hardhat-gas-reporter');
6
- require('solidity-coverage');
7
-
8
- const networks = require('./hardhat.networks');
9
-
10
- module.exports = {
11
- etherscan: {
12
- apiKey: process.env.ETHERSCAN_KEY,
13
- },
14
- solidity: {
15
- version: '0.8.9',
16
- settings: {
17
- optimizer: {
18
- enabled: true,
19
- runs: 1000000,
20
- },
21
- },
22
- },
23
- networks,
24
- namedAccounts: {
25
- deployer: {
26
- default: 0,
27
- },
28
- },
29
- gasReporter: {
30
- enable: true,
31
- currency: 'USD',
32
- },
33
- };
@@ -1,48 +0,0 @@
1
- const networks = {};
2
-
3
- if (process.env.MAINNET_RPC_URL && process.env.MAINNET_PRIVATE_KEY) {
4
- networks.mainnet = {
5
- url: process.env.MAINNET_RPC_URL,
6
- chainId: 1,
7
- gasPrice: 25000000000,
8
- accounts: [process.env.MAINNET_PRIVATE_KEY],
9
- };
10
- }
11
-
12
- if (process.env.BSC_RPC_URL && process.env.BSC_PRIVATE_KEY) {
13
- networks.bsc = {
14
- url: process.env.BSC_RPC_URL,
15
- chainId: 56,
16
- gasPrice: 10000000000,
17
- accounts: [process.env.BSC_PRIVATE_KEY],
18
- };
19
- }
20
-
21
- if (process.env.KOVAN_RPC_URL && process.env.KOVAN_PRIVATE_KEY) {
22
- networks.kovan = {
23
- url: process.env.KOVAN_RPC_URL,
24
- chainId: 42,
25
- gasPrice: 1000000000,
26
- accounts: [process.env.KOVAN_PRIVATE_KEY],
27
- };
28
- }
29
-
30
- if (process.env.MATIC_RPC_URL && process.env.MATIC_PRIVATE_KEY) {
31
- networks.matic = {
32
- url: process.env.MATIC_RPC_URL,
33
- chainId: 137,
34
- gasPrice: 1000000000,
35
- accounts: [process.env.MATIC_PRIVATE_KEY],
36
- };
37
- }
38
-
39
- if (process.env.ARBITRUM_RPC_URL && process.env.ARBITRUM_PRIVATE_KEY) {
40
- networks.arbitrum = {
41
- url: process.env.ARBITRUM_RPC_URL,
42
- chainId: 42161,
43
- gasPrice: 250000000,
44
- accounts: [process.env.ARBITRUM_PRIVATE_KEY],
45
- };
46
- }
47
-
48
- module.exports = networks;
package/test/asserts.js DELETED
@@ -1,88 +0,0 @@
1
- const { expect } = require('chai');
2
- const { assertThrowsAsync, assertRoughlyEqualValues } = require('../js/asserts.js');
3
-
4
- describe('assertThrowsAsync', async function () {
5
- async function action () {
6
- throw new Error('Test throw message');
7
- }
8
-
9
- it('shouldn\'t be thrown', async function () {
10
- try {
11
- await assertThrowsAsync(action, 'Test throw message');
12
- } catch (e) {
13
- expect(true).equal(false);
14
- }
15
- });
16
-
17
- it('should be thrown with no expected message', async function () {
18
- try {
19
- await assertThrowsAsync(action, 'Another test throw message');
20
- } catch (e) {
21
- expect(e.message).equal('expected \'Test throw message\' to include \'Another test throw message\'');
22
- return;
23
- }
24
- expect(true).equal(false);
25
- });
26
-
27
- it('should be thrown because function doesn\'t have throw', async function () {
28
- try {
29
- await assertThrowsAsync(async function () {}, 'Test throw message');
30
- } catch (e) {
31
- expect(e.message).equal('Should have thrown an error but didn\'t');
32
- return;
33
- }
34
- expect(true).equal(false);
35
- });
36
- });
37
-
38
- describe('assertRoughlyEqualValues', async function () {
39
- function shouldNotThrow (expected, actual, relativeDiff) {
40
- try {
41
- assertRoughlyEqualValues(expected, actual, relativeDiff);
42
- } catch (e) {
43
- expect(true).equal(false);
44
- }
45
- }
46
-
47
- function shouldThrow (expected, actual, relativeDiff) {
48
- try {
49
- assertRoughlyEqualValues(expected, actual, relativeDiff);
50
- } catch (e) {
51
- expect(e.message).equal(`${actual} != ${expected} with ${relativeDiff} precision: expected '${actual}' to equal '${expected}'`);
52
- return;
53
- }
54
- expect(true).equal(false);
55
- }
56
-
57
- it('should be work with expected = actual, any relativeDiff', async function () {
58
- shouldNotThrow(1000000, 1000000, 0.000001);
59
- });
60
-
61
- it('should be work with expected = actual, relativeDiff = 0', async function () {
62
- shouldNotThrow(1000000, 1000000, 0);
63
- });
64
-
65
- it('should be work with diff between expected and actual less than relativeDiff * expected', async function () {
66
- shouldNotThrow(1000001, 1000000, 1.000001);
67
- });
68
-
69
- it('should be work with negative diff between expected and actual less than relativeDiff * expected', async function () {
70
- shouldNotThrow(1000000, 1000001, 0.000001);
71
- });
72
-
73
- it('should be work with diff between expected and actual equals to relativeDiff', async function () {
74
- shouldNotThrow(1000000, 1000001, 1);
75
- });
76
-
77
- it('should be thrown with expected != actual with relativeDiff = 0', async function () {
78
- shouldThrow(1000000, 1000001, 0);
79
- });
80
-
81
- it('should be thrown with expected > actual more than relativeDiff * expected', async function () {
82
- shouldThrow(1000001, 1000000, 0.0000001);
83
- });
84
-
85
- it('should be thrown with expected < actual more than relativeDiff * expected', async function () {
86
- shouldThrow(1000000, 1000001, 0.0000001);
87
- });
88
- });
@@ -1,149 +0,0 @@
1
- const { expect } = require('chai');
2
- const { expectRevert, constants } = require('@openzeppelin/test-helpers');
3
-
4
- const AddressArrayMock = artifacts.require('AddressArrayMock');
5
-
6
- contract('AddressArray', async function ([wallet1, wallet2, wallet3]) {
7
- beforeEach(async function () {
8
- this.AddressArrayMock = await AddressArrayMock.new();
9
- });
10
-
11
- describe('length', async function () {
12
- it('should be calculate length 0', async function () {
13
- expect(await this.AddressArrayMock.length()).to.be.bignumber.equal('0');
14
- });
15
-
16
- it('should be calculate length 1', async function () {
17
- await this.AddressArrayMock.push(wallet1);
18
- expect(await this.AddressArrayMock.length()).to.be.bignumber.equal('1');
19
- });
20
- });
21
-
22
- describe('at', async function () {
23
- it('should be get from empty data', async function () {
24
- expect(await this.AddressArrayMock.at(0)).to.be.equal(constants.ZERO_ADDRESS);
25
- expect(await this.AddressArrayMock.at(1)).to.be.equal(constants.ZERO_ADDRESS);
26
- });
27
-
28
- it('should be get from data with 1 element', async function () {
29
- await this.AddressArrayMock.push(wallet1);
30
- expect(await this.AddressArrayMock.at(0)).to.be.equal(wallet1);
31
- expect(await this.AddressArrayMock.at(1)).to.be.equal(constants.ZERO_ADDRESS);
32
- });
33
-
34
- it('should be get from data with several elements', async function () {
35
- await this.AddressArrayMock.push(wallet1);
36
- await this.AddressArrayMock.push(wallet2);
37
- expect(await this.AddressArrayMock.at(0)).to.be.equal(wallet1);
38
- expect(await this.AddressArrayMock.at(1)).to.be.equal(wallet2);
39
- });
40
- });
41
-
42
- describe('get', async function () {
43
- it('should be get empty data', async function () {
44
- expect(await this.AddressArrayMock.get()).to.eql([]);
45
- });
46
-
47
- it('should be get from data with 1 element', async function () {
48
- await this.AddressArrayMock.push(wallet1);
49
- expect(await this.AddressArrayMock.get()).to.eql([wallet1]);
50
- });
51
-
52
- it('should be get from data with several elements', async function () {
53
- await this.AddressArrayMock.push(wallet1);
54
- await this.AddressArrayMock.push(wallet2);
55
- expect(await this.AddressArrayMock.get()).to.eql([wallet1, wallet2]);
56
- });
57
- });
58
-
59
- describe('push', async function () {
60
- it('should be push to empty data', async function () {
61
- const pushedIndex = await this.AddressArrayMock.push.call(wallet1);
62
- await this.AddressArrayMock.push(wallet1);
63
- expect(await this.AddressArrayMock.at(pushedIndex - 1)).to.be.equal(wallet1);
64
- });
65
-
66
- it('should be push to data with 1 element', async function () {
67
- await this.AddressArrayMock.push(wallet1);
68
- const pushedIndex = await this.AddressArrayMock.push.call(wallet2);
69
- await this.AddressArrayMock.push(wallet2);
70
- expect(await this.AddressArrayMock.at(pushedIndex - 1)).to.be.equal(wallet2);
71
- });
72
-
73
- it('should be get push to data with several elements', async function () {
74
- await this.AddressArrayMock.push(wallet1);
75
- await this.AddressArrayMock.push(wallet2);
76
- const pushedIndex = await this.AddressArrayMock.push.call(wallet3);
77
- await this.AddressArrayMock.push(wallet3);
78
- expect(await this.AddressArrayMock.at(pushedIndex - 1)).to.be.equal(wallet3);
79
- });
80
- });
81
-
82
- describe('pop', async function () {
83
- it('should be thrown when data is empty', async function () {
84
- await expectRevert(
85
- this.AddressArrayMock.pop(),
86
- 'AddressArray: popping from empty',
87
- );
88
- });
89
-
90
- it('should be pop in data with 1 element', async function () {
91
- await this.AddressArrayMock.push(wallet1);
92
- await this.AddressArrayMock.pop();
93
- expect(await this.AddressArrayMock.get()).to.eql([]);
94
- });
95
-
96
- it('should be pop in data with several elements', async function () {
97
- await this.AddressArrayMock.push(wallet1);
98
- await this.AddressArrayMock.push(wallet2);
99
- await this.AddressArrayMock.pop();
100
- expect(await this.AddressArrayMock.get()).to.eql([wallet1]);
101
- });
102
-
103
- it('should be several pops', async function () {
104
- await this.AddressArrayMock.push(wallet1);
105
- await this.AddressArrayMock.push(wallet2);
106
- await this.AddressArrayMock.push(wallet3);
107
- await this.AddressArrayMock.pop();
108
- expect(await this.AddressArrayMock.get()).to.eql([wallet1, wallet2]);
109
- });
110
-
111
- it('should be thrown when pops more than elements', async function () {
112
- await this.AddressArrayMock.push(wallet1);
113
- await this.AddressArrayMock.pop();
114
- await expectRevert(
115
- this.AddressArrayMock.pop(),
116
- 'AddressArray: popping from empty',
117
- );
118
- });
119
- });
120
-
121
- describe('set', async function () {
122
- it('should be thrown when set index less than data length', async function () {
123
- await expectRevert(
124
- this.AddressArrayMock.set(0, wallet1),
125
- 'AddressArray: index out of range',
126
- );
127
- });
128
-
129
- it('should be set to index 0 to data with 1 element', async function () {
130
- await this.AddressArrayMock.push(wallet1);
131
- await this.AddressArrayMock.set(0, wallet2);
132
- expect(await this.AddressArrayMock.get()).to.eql([wallet2]);
133
- });
134
-
135
- it('should be set to index 0 to data with several elements', async function () {
136
- await this.AddressArrayMock.push(wallet1);
137
- await this.AddressArrayMock.push(wallet2);
138
- await this.AddressArrayMock.set(0, wallet3);
139
- expect(await this.AddressArrayMock.get()).to.eql([wallet3, wallet2]);
140
- });
141
-
142
- it('should be set to index non-0 to data with several elements', async function () {
143
- await this.AddressArrayMock.push(wallet1);
144
- await this.AddressArrayMock.push(wallet2);
145
- await this.AddressArrayMock.set(1, wallet3);
146
- expect(await this.AddressArrayMock.get()).to.eql([wallet1, wallet3]);
147
- });
148
- });
149
- });
@@ -1,122 +0,0 @@
1
- const { expect } = require('chai');
2
- const { constants } = require('@openzeppelin/test-helpers');
3
-
4
- const AddressSetMock = artifacts.require('AddressSetMock');
5
-
6
- contract('AddressSet', async function ([wallet1, wallet2, wallet3]) {
7
- beforeEach(async function () {
8
- this.AddressSetMock = await AddressSetMock.new();
9
- });
10
-
11
- describe('length', async function () {
12
- it('should be calculate length 0', async function () {
13
- expect(await this.AddressSetMock.length()).to.be.bignumber.equal('0');
14
- });
15
-
16
- it('should be calculate length 1', async function () {
17
- await this.AddressSetMock.add(wallet1);
18
- expect(await this.AddressSetMock.length()).to.be.bignumber.equal('1');
19
- });
20
- });
21
-
22
- describe('at', async function () {
23
- it('should be get from empty data', async function () {
24
- expect(await this.AddressSetMock.at(0)).to.be.equal(constants.ZERO_ADDRESS);
25
- expect(await this.AddressSetMock.at(1)).to.be.equal(constants.ZERO_ADDRESS);
26
- });
27
-
28
- it('should be get from data with 1 element', async function () {
29
- await this.AddressSetMock.add(wallet1);
30
- expect(await this.AddressSetMock.at(0)).to.be.equal(wallet1);
31
- expect(await this.AddressSetMock.at(1)).to.be.equal(constants.ZERO_ADDRESS);
32
- });
33
-
34
- it('should be get from data with several elements', async function () {
35
- await this.AddressSetMock.add(wallet1);
36
- await this.AddressSetMock.add(wallet2);
37
- expect(await this.AddressSetMock.at(0)).to.be.equal(wallet1);
38
- expect(await this.AddressSetMock.at(1)).to.be.equal(wallet2);
39
- });
40
- });
41
-
42
- describe('contains', async function () {
43
- it('should be not contains in empty data', async function () {
44
- expect(await this.AddressSetMock.contains(wallet1)).to.be.equal(false);
45
- expect(await this.AddressSetMock.contains(wallet2)).to.be.equal(false);
46
- expect(await this.AddressSetMock.contains(constants.ZERO_ADDRESS)).to.be.equal(false);
47
- });
48
-
49
- it('should be contains address', async function () {
50
- await this.AddressSetMock.add(wallet1);
51
- expect(await this.AddressSetMock.contains(wallet1)).to.be.equal(true);
52
- expect(await this.AddressSetMock.contains(wallet2)).to.be.equal(false);
53
- expect(await this.AddressSetMock.contains(constants.ZERO_ADDRESS)).to.be.equal(false);
54
- });
55
-
56
- it('should be contains addresses', async function () {
57
- await this.AddressSetMock.add(wallet1);
58
- await this.AddressSetMock.add(wallet2);
59
- expect(await this.AddressSetMock.contains(wallet1)).to.be.equal(true);
60
- expect(await this.AddressSetMock.contains(wallet2)).to.be.equal(true);
61
- expect(await this.AddressSetMock.contains(wallet3)).to.be.equal(false);
62
- expect(await this.AddressSetMock.contains(constants.ZERO_ADDRESS)).to.be.equal(false);
63
- });
64
- });
65
-
66
- describe('add', async function () {
67
- it('should be add to empty data', async function () {
68
- const isAdded = await this.AddressSetMock.add.call(wallet1);
69
- await this.AddressSetMock.add(wallet1);
70
- expect(await this.AddressSetMock.contains(wallet1)).to.be.equal(isAdded);
71
- });
72
-
73
- it('should not be add a double element without another elements in data', async function () {
74
- await this.AddressSetMock.add(wallet1);
75
- expect(await this.AddressSetMock.add.call(wallet1)).to.be.equal(false);
76
- });
77
-
78
- it('should be add to data with 1 element', async function () {
79
- await this.AddressSetMock.add(wallet1);
80
- const isAdded = await this.AddressSetMock.add.call(wallet2);
81
- await this.AddressSetMock.add(wallet2);
82
- expect(await this.AddressSetMock.contains(wallet2)).to.be.equal(isAdded);
83
- });
84
-
85
- it('should not be add a double element with another elements in data', async function () {
86
- await this.AddressSetMock.add(wallet1);
87
- await this.AddressSetMock.add(wallet2);
88
- expect(await this.AddressSetMock.add.call(wallet2)).to.be.equal(false);
89
- });
90
- });
91
-
92
- describe('remove', async function () {
93
- it('should not be remove from empty data', async function () {
94
- const isRemoved = await this.AddressSetMock.remove.call(wallet1);
95
- expect(isRemoved).to.be.equal(false);
96
- });
97
-
98
- it('should be remove from data', async function () {
99
- await this.AddressSetMock.add(wallet1);
100
- const isRemoved = await this.AddressSetMock.remove.call(wallet1);
101
- await this.AddressSetMock.remove(wallet1);
102
- expect(isRemoved).to.be.equal(true);
103
- expect(await this.AddressSetMock.contains(wallet1)).to.be.equal(false);
104
- });
105
-
106
- it('should not be remove element which is not in data', async function () {
107
- await this.AddressSetMock.add(wallet1);
108
- const isRemoved = await this.AddressSetMock.remove.call(wallet2);
109
- expect(isRemoved).to.be.equal(false);
110
- });
111
-
112
- it('should be remove from data and keep the remainder', async function () {
113
- await this.AddressSetMock.add(wallet1);
114
- await this.AddressSetMock.add(wallet2);
115
- const isRemoved = await this.AddressSetMock.remove.call(wallet1);
116
- await this.AddressSetMock.remove(wallet1);
117
- expect(isRemoved).to.be.equal(true);
118
- expect(await this.AddressSetMock.contains(wallet1)).to.be.equal(false);
119
- expect(await this.AddressSetMock.contains(wallet2)).to.be.equal(true);
120
- });
121
- });
122
- });
@@ -1,45 +0,0 @@
1
- const { expectRevert } = require('@openzeppelin/test-helpers');
2
-
3
- const RevertReasonParserTest = artifacts.require('RevertReasonParserTest');
4
-
5
- describe('RevertReasonParser', async () => {
6
- before(async function () {
7
- this.RevertReasonParserTest = await RevertReasonParserTest.new();
8
- });
9
-
10
- describe('parse', async function () {
11
- it('should be reverted with Invalid revert reason', async function () {
12
- await expectRevert(
13
- this.RevertReasonParserTest.testParseWithThrow(),
14
- 'Invalid revert reason',
15
- );
16
- });
17
-
18
- it('should be parsed as empty Error', async function () {
19
- await this.RevertReasonParserTest.testEmptyStringRevert();
20
- });
21
-
22
- it('should be parsed as Error', async function () {
23
- await this.RevertReasonParserTest.testNonEmptyRevert();
24
- });
25
-
26
- it('should be parsed as Unknown', async function () {
27
- await this.RevertReasonParserTest.testEmptyRevert();
28
- });
29
-
30
- it('should be parsed as Panic', async function () {
31
- await this.RevertReasonParserTest.testAssertion();
32
- });
33
-
34
- it('should be parsed as Error with long string', async function () {
35
- await this.RevertReasonParserTest.testLongStringRevert();
36
- });
37
-
38
- it('should be reverted in _test()', async function () {
39
- await expectRevert(
40
- this.RevertReasonParserTest.testWithThrow(),
41
- 'testFunctions without throw',
42
- );
43
- });
44
- });
45
- });