From fc2f48d306cf4bfedf359a8f38b615339687b10e Mon Sep 17 00:00:00 2001 From: RiccardoBiosas Date: Tue, 12 Jul 2022 15:16:33 -0500 Subject: [PATCH 1/5] tests(foundry): converted all the truffle-based unit tests to Foundry --- src/test/unit/TestEarningsPool.sol | 31 ++++ src/test/unit/TestEarningsPoolLIP36.sol | 70 ++++++++ src/test/unit/TestMathUtils.sol | 32 ++++ src/test/unit/TestMathUtilsV2.sol | 33 ++++ src/test/unit/TestPreciseMathUtils.sol | 41 +++++ .../unit/TestSortedDoublyLLFindWithHints.sol | 151 ++++++++++++++++++ .../TestSortedDoublyLLFindWithHintsV2.sol | 126 +++++++++++++++ src/test/unit/TestSortedDoublyLLInsert.sol | 112 +++++++++++++ src/test/unit/TestSortedDoublyLLRemove.sol | 79 +++++++++ src/test/unit/TestSortedDoublyLLUpdateKey.sol | 73 +++++++++ 10 files changed, 748 insertions(+) create mode 100644 src/test/unit/TestEarningsPool.sol create mode 100644 src/test/unit/TestEarningsPoolLIP36.sol create mode 100644 src/test/unit/TestMathUtils.sol create mode 100644 src/test/unit/TestMathUtilsV2.sol create mode 100644 src/test/unit/TestPreciseMathUtils.sol create mode 100644 src/test/unit/TestSortedDoublyLLFindWithHints.sol create mode 100644 src/test/unit/TestSortedDoublyLLFindWithHintsV2.sol create mode 100644 src/test/unit/TestSortedDoublyLLInsert.sol create mode 100644 src/test/unit/TestSortedDoublyLLRemove.sol create mode 100644 src/test/unit/TestSortedDoublyLLUpdateKey.sol diff --git a/src/test/unit/TestEarningsPool.sol b/src/test/unit/TestEarningsPool.sol new file mode 100644 index 00000000..1f757606 --- /dev/null +++ b/src/test/unit/TestEarningsPool.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "ds-test/test.sol"; +import "contracts/test/mocks/EarningsPoolFixture.sol"; +import "../interfaces/ICheatCodes.sol"; + +contract TestEarningsPool is DSTest { + ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); + EarningsPoolFixture fixture; + + function setUp() public { + fixture = new EarningsPoolFixture(); + fixture.setStake(1000); + fixture.setCommission(500000, 500000); + } + + function testSetCommission() public { + fixture.setCommission(5, 10); + uint256 transcoderRewardCut = fixture.getTranscoderRewardCut(); + uint256 transcoderFeeShare = fixture.getTranscoderFeeShare(); + assertEq(transcoderRewardCut, 5, "wrong transcoderRewardCut"); + assertEq(transcoderFeeShare, 10, "wrong transcoderFeeShare"); + } + + function testSetStake() public { + fixture.setStake(5000); + uint256 totalStake = fixture.getTotalStake(); + assertEq(totalStake, 5000, "wrong totalStake"); + } +} diff --git a/src/test/unit/TestEarningsPoolLIP36.sol b/src/test/unit/TestEarningsPoolLIP36.sol new file mode 100644 index 00000000..8f3f317d --- /dev/null +++ b/src/test/unit/TestEarningsPoolLIP36.sol @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "ds-test/test.sol"; +import "contracts/test/mocks/EarningsPoolFixture.sol"; +import "contracts/libraries/PreciseMathUtils.sol"; +import "../interfaces/ICheatCodes.sol"; + +contract TestEarningsPoolLIP36 is DSTest { + ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); + EarningsPoolFixture fixture; + + function setUp() public { + fixture = new EarningsPoolFixture(); + fixture.setStake(1000); + fixture.setCommission(500000, 500000); + } + + function testUpdateCumulativeFeeFactorWithNoPrevEarningsPool() public { + uint256 fees = 1000; + + // earningsPool.cumulativeFeeFactor == 0 + // prevEarningsPool.cumulativeFeeFactor == 0 + // prevEarningsPool.cumulativeRewardFactor == 0 + fixture.updateCumulativeFeeFactor(fees); + uint256 expFeeFactor = PreciseMathUtils.percPoints(fees, fixture.getTotalStake()); + assertEq(fixture.getCumulativeFeeFactor(), expFeeFactor, "should set cumulativeFeeFactor"); + + // earningsPool.cumulativeFeeFactor != 0 + fixture.updateCumulativeFeeFactor(fees); + expFeeFactor += PreciseMathUtils.percPoints(fees, fixture.getTotalStake()); + assertEq(fixture.getCumulativeFeeFactor(), expFeeFactor, "should update cumulativeFeeFactor"); + } + + function testUpdateCumulativeFeeFactorWithPrevEarningsPool() public { + uint256 fees = 200; + + // prevEarningsPool.cumulativeFeeFactor = 2 + // prevEarningsPool.cumulativeRewardFactor = 3 + uint256 prevFeeFactor = 2; + uint256 prevRewFactor = 3; + fixture.setPrevPoolEarningsFactors(prevFeeFactor, prevRewFactor); + + // earningsPool.cumulativeFeeFactor == 0 + fixture.updateCumulativeFeeFactor(fees); + uint256 expFeeFactor = prevFeeFactor + PreciseMathUtils.percOf(prevRewFactor, fees, fixture.getTotalStake()); + assertEq(fixture.getCumulativeFeeFactor(), expFeeFactor, "should update cumulativeFeeFactor"); + + // earningsPool.cumulativeFeeFactor != 0 + fixture.updateCumulativeFeeFactor(fees); + expFeeFactor += PreciseMathUtils.percOf(prevRewFactor, fees, fixture.getTotalStake()); + } + + function testUpdateCumulativeRewardFactor() public { + uint256 rewards = 1000; + + // prevEarningsPool.cumulativeRewardFactor == 0 + uint256 expRewardFactor = PreciseMathUtils.percPoints(1, 1) + + PreciseMathUtils.percOf(PreciseMathUtils.percPoints(1, 1), rewards, fixture.getTotalStake()); + + fixture.updateCumulativeRewardFactor(1000); + assertEq(expRewardFactor, fixture.getCumulativeRewardFactor(), "incorrect cumulative reward factor"); + + // prevEarningsPool.cumulativeRewardFactor != 0 + fixture.setPrevPoolEarningsFactors(0, expRewardFactor); + expRewardFactor += PreciseMathUtils.percOf(expRewardFactor, rewards, fixture.getTotalStake()); + fixture.updateCumulativeRewardFactor(1000); + assertEq(expRewardFactor, fixture.getCumulativeRewardFactor(), "incorrect cumulative reward factor"); + } +} diff --git a/src/test/unit/TestMathUtils.sol b/src/test/unit/TestMathUtils.sol new file mode 100644 index 00000000..29ced695 --- /dev/null +++ b/src/test/unit/TestMathUtils.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "ds-test/test.sol"; +import "../interfaces/ICheatCodes.sol"; +import "contracts/libraries/MathUtils.sol"; + +contract TestMathUtils is DSTest { + ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); + + function testValidPerc() public { + assertTrue(MathUtils.validPerc(50), "50 should be a valid percentage"); + assertTrue(MathUtils.validPerc(0), "0 should be a valid percentage"); + assertTrue(MathUtils.validPerc(1000000), "the max should be a valid percentage"); + assertTrue(!MathUtils.validPerc(1000001), "1 more than the max should not be valid percentage"); + } + + function testPercOf1() public { + assertEq(MathUtils.percOf(100, 3, 4), 75, "3/4 of 100 should be 75"); + assertEq(MathUtils.percOf(100, 7, 9), 77, "7/9 of 100 should be 77"); + } + + function testPercOf2() public { + assertEq(MathUtils.percOf(100, 3), 0, ".0003% of 100 is 0"); + assertEq(MathUtils.percOf(100, 100000), 10, "10% of 100 is 10"); + } + + function testPercPoints() public { + assertEq(MathUtils.percPoints(3, 4), 750000, "3/4 should convert to valid percentage"); + assertEq(MathUtils.percPoints(100, 300), 333333, "100/300 should convert to valid percentage"); + } +} diff --git a/src/test/unit/TestMathUtilsV2.sol b/src/test/unit/TestMathUtilsV2.sol new file mode 100644 index 00000000..8a1420fe --- /dev/null +++ b/src/test/unit/TestMathUtilsV2.sol @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "ds-test/test.sol"; +import "contracts/libraries/MathUtilsV2.sol"; +import "../interfaces/ICheatCodes.sol"; + +contract TestMathUtilsV2 is DSTest { + ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); + + function testValidPerc() public { + assertTrue(MathUtils.validPerc(50), "50 should be a valid percentage"); + assertTrue(MathUtils.validPerc(0), "0 should be a valid percentage"); + assertTrue(MathUtils.validPerc(1000000000), "the max should be a valid percentage"); + assertTrue(!MathUtils.validPerc(1000000001), "1 more than the max should not be valid percentage"); + } + + function testPercOf1() public { + assertEq(MathUtils.percOf(100, 3, 4), 75, "3/4 of 100 should be 75"); + assertEq(MathUtils.percOf(100, 7, 9), 77, "7/9 of 100 should be 77"); + } + + function testPercOf2() public { + assertEq(MathUtils.percOf(100, 3), 0, ".0000003% of 100 is 0"); + assertEq(MathUtils.percOf(1000000000, 1), 1, ".0000001% of 1000000000 is 1"); + assertEq(MathUtils.percOf(100, 100000000), 10, "10% of 100 is 10"); + } + + function testPercPoints() public { + assertEq(MathUtils.percPoints(3, 4), 750000000, "3/4 should convert to valid percentage"); + assertEq(MathUtils.percPoints(100, 300), 333333333, "100/300 should convert to valid percentage"); + } +} diff --git a/src/test/unit/TestPreciseMathUtils.sol b/src/test/unit/TestPreciseMathUtils.sol new file mode 100644 index 00000000..8ebc9607 --- /dev/null +++ b/src/test/unit/TestPreciseMathUtils.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "ds-test/test.sol"; +import "contracts/libraries/PreciseMathUtils.sol"; +import "../interfaces/ICheatCodes.sol"; + +contract TestPreciseMathUtils is DSTest { + ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); + + function testValidPerc() public { + assertTrue(PreciseMathUtils.validPerc(50), "50 should be a valid percentage"); + assertTrue(PreciseMathUtils.validPerc(0), "0 should be a valid percentage"); + assertTrue(PreciseMathUtils.validPerc(10**27), "the max should be a valid percentage"); + assertTrue(!PreciseMathUtils.validPerc(10**27 + 1), "1 more than the max should not be valid percentage"); + } + + function testPercOf1() public { + assertEq(PreciseMathUtils.percOf(100, 3, 4), 75, "3/4 of 100 should be 75"); + assertEq(PreciseMathUtils.percOf(100, 7, 9), 77, "7/9 of 100 should be 77"); + } + + function testPercOf2() public { + assertEq(PreciseMathUtils.percOf(100, 3), 0, ".0000000000000000000000003% of 100 is 0"); + assertEq(PreciseMathUtils.percOf(10**27, 1), 1, ".0000000000000000000000001% of 1000000000 is 1"); + assertEq(PreciseMathUtils.percOf(100, 10**27 / 10), 10, "10% of 100 is 10"); + } + + function testPercPoints() public { + assertEq( + PreciseMathUtils.percPoints(3, 4), + 750000000000000000000000000, + "3/4 should convert to valid percentage" + ); + assertEq( + PreciseMathUtils.percPoints(100, 300), + 333333333333333333333333333, + "100/300 should convert to valid percentage" + ); + } +} diff --git a/src/test/unit/TestSortedDoublyLLFindWithHints.sol b/src/test/unit/TestSortedDoublyLLFindWithHints.sol new file mode 100644 index 00000000..bac94a4d --- /dev/null +++ b/src/test/unit/TestSortedDoublyLLFindWithHints.sol @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "ds-test/test.sol"; +import "../interfaces/ICheatCodes.sol"; +import "contracts/test/mocks/SortedDoublyLLFixture.sol"; + +contract TestSortedDoublyLLFindWithHints is DSTest { + ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); + + address[] ids = [address(1), address(2), address(3), address(4), address(5), address(6)]; + uint256[] keys = [uint256(13), uint256(11), uint256(9), uint256(7), uint256(5), uint256(3)]; + + SortedDoublyLLFixture fixture; + + function setUp() public { + fixture = new SortedDoublyLLFixture(); + fixture.setMaxSize(10); + } + + function testInsertFindNoHintUpdateHead() public { + fixture.insert(ids[1], keys[1], address(0), address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[3], keys[3], ids[2], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.insert(ids[0], keys[0], address(0), address(0)); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getFirst(), ids[0], "wrong head"); + assertEq(fixture.getKey(ids[0]), keys[0], "wrong key"); + assertEq(fixture.getNext(ids[0]), ids[1], "wrong next"); + assertEq(fixture.getPrev(ids[0]), address(0), "wrong prev"); + } + + function testInsertFindNoHintUpdateTail() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[3], keys[3], ids[2], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + + fixture.insert(ids[5], keys[5], address(0), address(0)); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getLast(), ids[5], "wrong tail"); + assertEq(fixture.getKey(ids[5]), keys[5], "wrong key"); + assertEq(fixture.getNext(ids[5]), address(0), "wrong next transcoder"); + assertEq(fixture.getPrev(ids[5]), ids[4], "wrong prev transcoder"); + } + + function testInsertFindNoHintAtPosition() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[3], keys[3], ids[1], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.insert(ids[2], keys[2], address(0), address(0)); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getKey(ids[2]), keys[2], "wrong"); + assertEq(fixture.getNext(ids[2]), ids[3], "wrong next"); + assertEq(fixture.getPrev(ids[2]), ids[1], "wrong prev"); + } + + function testInsertFindWithHintNextUpdateHead() public { + fixture.insert(ids[1], keys[1], address(0), address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[3], keys[3], ids[2], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.insert(ids[0], keys[0], address(0), ids[2]); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getFirst(), ids[0], "wrong head"); + assertEq(fixture.getKey(ids[0]), keys[0], "wrong key"); + assertEq(fixture.getNext(ids[0]), ids[1], "wrong next"); + assertEq(fixture.getPrev(ids[0]), address(0), "wrong prev"); + } + + function testInsertFindWithHintNextUpdateTail() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[3], keys[3], ids[2], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.insert(ids[1], 3, address(0), ids[5]); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getLast(), ids[1], "wrong tail"); + assertEq(fixture.getKey(ids[1]), 3, "wrong key"); + assertEq(fixture.getNext(ids[1]), address(0), "wrong next"); + assertEq(fixture.getPrev(ids[1]), ids[5], "wrong prev"); + } + + function testInsertFindWithHintNextAtPosition() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[3], keys[3], ids[1], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.insert(ids[2], keys[2], address(0), ids[3]); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getKey(ids[2]), keys[2], "wrong key"); + assertEq(fixture.getNext(ids[2]), ids[3], "wrong next"); + assertEq(fixture.getPrev(ids[2]), ids[1], "wrong prev"); + } + + function testInsertFindWithHintPrevUpdateTail() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[3], keys[3], ids[1], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + + fixture.insert(ids[5], keys[5], ids[1], address(0)); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getLast(), ids[5], "wrong tail"); + assertEq(fixture.getKey(ids[5]), keys[5], "wrong key"); + assertEq(fixture.getNext(ids[5]), address(0), "wrong next"); + assertEq(fixture.getPrev(ids[5]), ids[4], "wrong prev"); + } + + function testInsertFindWithHintPrevAtPosition() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[3], keys[3], ids[1], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.insert(ids[2], keys[2], ids[0], address(0)); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getKey(ids[2]), keys[2], "wrong key"); + assertEq(fixture.getNext(ids[2]), ids[3], "wrong next"); + assertEq(fixture.getPrev(ids[2]), ids[1], "wrong prev"); + } + + function testInsertFindWithHint() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[4], keys[4], ids[2], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.insert(ids[3], keys[3], ids[2], ids[4]); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getKey(ids[3]), keys[3], "wrong key"); + assertEq(fixture.getNext(ids[3]), ids[4], "wrong next"); + assertEq(fixture.getPrev(ids[3]), ids[2], "wrong prev"); + } +} diff --git a/src/test/unit/TestSortedDoublyLLFindWithHintsV2.sol b/src/test/unit/TestSortedDoublyLLFindWithHintsV2.sol new file mode 100644 index 00000000..c6bdb296 --- /dev/null +++ b/src/test/unit/TestSortedDoublyLLFindWithHintsV2.sol @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "ds-test/test.sol"; +import "../interfaces/ICheatCodes.sol"; +import "contracts/test/mocks/SortedDoublyLLFixture.sol"; + +contract TestSortedDoublyLLFindWithHintsV2 is DSTest { + ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); + + address[] ids = [address(1), address(2), address(3), address(4), address(5), address(6)]; + uint256[] keys = [uint256(13), uint256(11), uint256(9), uint256(7), uint256(5), uint256(3)]; + + SortedDoublyLLFixture fixture; + + function setUp() public { + fixture = new SortedDoublyLLFixture(); + fixture.setMaxSize(10); + } + + function testInsertFindWithHintPrevRemoved() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[4], keys[4], ids[2], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.remove(ids[2]); + fixture.insert(ids[3], keys[3], ids[2], ids[4]); + assertEq(fixture.getSize(), 5, "wrong size"); + assertEq(fixture.getKey(ids[3]), keys[3], "wrong key"); + assertEq(fixture.getNext(ids[3]), ids[4], "wrong next"); + assertEq(fixture.getPrev(ids[3]), ids[1], "wrong prev"); + } + + function testInsertFindWithHintPrevRemovedUpdateHead() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[3], keys[3], ids[2], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.remove(ids[0]); + fixture.insert(ids[1], keys[1], ids[0], ids[2]); + assertEq(fixture.getSize(), 5, "wrong size"); + assertEq(fixture.getFirst(), ids[1], "wrong head"); + assertEq(fixture.getKey(ids[1]), keys[1], "wrong key"); + assertEq(fixture.getNext(ids[1]), ids[2], "wrong next"); + assertEq(fixture.getPrev(ids[1]), address(0), "wrong prev"); + } + + function testInsertFindWithHintPrevDecreased() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[4], keys[4], ids[2], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.updateKey(ids[2], 6, address(0), address(0)); + fixture.insert(ids[3], keys[3], ids[2], ids[4]); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getKey(ids[3]), keys[3], "wrong key"); + assertEq(fixture.getNext(ids[3]), ids[2], "wrong next"); + assertEq(fixture.getPrev(ids[3]), ids[1], "wrong prev"); + } + + function testInsertWithFindWithHintNextRemoved() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[4], keys[4], ids[2], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.remove(ids[4]); + fixture.insert(ids[3], keys[3], ids[2], ids[4]); + assertEq(fixture.getSize(), 5, "wrong size"); + assertEq(fixture.getKey(ids[3]), keys[3], "wrong key"); + assertEq(fixture.getNext(ids[3]), ids[5], "wrong next"); + assertEq(fixture.getPrev(ids[3]), ids[2], "wrong prev"); + } + + function testInsertWithFindWithHintNextRemovedUpdateTail() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[3], keys[3], ids[2], address(0)); + fixture.insert(ids[5], keys[5], ids[3], address(0)); + + fixture.remove(ids[5]); + fixture.insert(ids[4], keys[4], ids[3], ids[5]); + assertEq(fixture.getSize(), 5, "wrong size"); + assertEq(fixture.getLast(), ids[4], "wrong tail"); + assertEq(fixture.getKey(ids[4]), keys[4], "wrong key"); + assertEq(fixture.getNext(ids[4]), address(0), "wrong next"); + assertEq(fixture.getPrev(ids[4]), ids[3], "wrong prev"); + } + + function testInsertWithfindWithHintNextIncreased() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[4], keys[4], ids[2], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.updateKey(ids[4], 8, address(0), address(0)); + fixture.insert(ids[3], keys[3], ids[2], ids[4]); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getKey(ids[3]), keys[3], "wrong key"); + assertEq(fixture.getNext(ids[3]), ids[5], "wrong next"); + assertEq(fixture.getPrev(ids[3]), ids[4], "wrong prev"); + } + + function testInsertWithFindWithHintNotTightBound() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[4], keys[4], ids[2], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + fixture.insert(ids[3], keys[3], ids[0], ids[5]); + assertEq(fixture.getSize(), 6, "wrong size"); + assertEq(fixture.getKey(ids[3]), keys[3], "wrong key"); + assertEq(fixture.getNext(ids[3]), ids[4], "wrong next"); + assertEq(fixture.getPrev(ids[3]), ids[2], "wrong prev"); + } +} diff --git a/src/test/unit/TestSortedDoublyLLInsert.sol b/src/test/unit/TestSortedDoublyLLInsert.sol new file mode 100644 index 00000000..6b3b9c97 --- /dev/null +++ b/src/test/unit/TestSortedDoublyLLInsert.sol @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "ds-test/test.sol"; +import "../interfaces/ICheatCodes.sol"; +import "contracts/test/mocks/SortedDoublyLLFixture.sol"; +import "contracts/test/helpers/RevertProxy.sol"; + +contract TestSortedDoublyLLInsert is DSTest { + ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); + + address[] ids = [address(1), address(2), address(3), address(4), address(5), address(6)]; + uint256[] keys = [uint256(13), uint256(11), uint256(9), uint256(7), uint256(5), uint256(5), uint256(3)]; + + SortedDoublyLLFixture fixture; + RevertProxy proxy; + + function setUp() public { + proxy = new RevertProxy(); + fixture = new SortedDoublyLLFixture(); + fixture.setMaxSize(3); + } + + function testSetMaxSize() public { + assertEq(fixture.getMaxSize(), 3, "wrong max size"); + } + + function testSetMaxSizeUpdate() public { + fixture.setMaxSize(10); + + assertEq(fixture.getMaxSize(), 10, "wrong max size"); + } + + function testSetMaxSizeDecreaseSize() public { + SortedDoublyLLFixture(address(proxy)).setMaxSize(1); + bool result = proxy.execute(address(fixture)); + assertTrue(!result, "did not revert"); + } + + function testInsertEmpty() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + assertEq(fixture.getSize(), 1, "wrong size"); + assertEq(fixture.getFirst(), ids[0], "wrong head"); + assertEq(fixture.getLast(), ids[0], "wrong tail"); + assertEq(fixture.getKey(ids[0]), keys[0], "wrong key"); + assertEq(fixture.getNext(ids[0]), address(0), "wrong next"); + assertEq(fixture.getPrev(ids[0]), address(0), "wrong prev"); + } + + function testInsertUpdateHead() public { + fixture.insert(ids[1], keys[1], address(0), address(0)); + + fixture.insert(ids[0], keys[0], address(0), ids[1]); + assertEq(fixture.getSize(), 2, "wrong size"); + assertEq(fixture.getFirst(), ids[0], "wrong head"); + assertEq(fixture.getKey(ids[0]), keys[0], "wrong key"); + assertEq(fixture.getNext(ids[0]), ids[1], "wrong next"); + assertEq(fixture.getPrev(ids[0]), address(0), "wrong prev"); + } + + function testInsertUpdateTail() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + + fixture.insert(ids[1], keys[1], ids[0], address(0)); + assertEq(fixture.getSize(), 2, "wrong size"); + assertEq(fixture.getLast(), ids[1], "wrong tail"); + assertEq(fixture.getKey(ids[1]), keys[1], "wrong key"); + assertEq(fixture.getNext(ids[1]), address(0), "wrong next"); + assertEq(fixture.getPrev(ids[1]), ids[0], "wrong prev"); + } + + function testInsertAtPosition() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[2], keys[2], ids[0], address(0)); + + fixture.insert(ids[1], keys[1], ids[0], ids[2]); + assertEq(fixture.getSize(), 3, "wrong size"); + assertEq(fixture.getKey(ids[1]), keys[1], "wrong stake"); + assertEq(fixture.getNext(ids[1]), ids[2], "wrong next transcoder"); + assertEq(fixture.getPrev(ids[1]), ids[0], "wrong prev transcoder"); + } + + function testInsertFull() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + + SortedDoublyLLFixture(address(proxy)).insert(ids[3], keys[3], address(0), address(0)); + bool result = proxy.execute(address(fixture)); + assertTrue(!result, "did not revert"); + } + + function testInsertContainsId() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + + SortedDoublyLLFixture(address(proxy)).insert(ids[0], keys[0], address(0), address(0)); + bool result = proxy.execute(address(fixture)); + assertTrue(!result, "did not revert"); + } + + function testInsertNull() public { + SortedDoublyLLFixture(address(proxy)).insert(address(0), keys[0], address(0), address(0)); + bool result = proxy.execute(address(fixture)); + assertTrue(!result, "did not revert"); + } + + function testInsertZeroKey() public { + SortedDoublyLLFixture(address(proxy)).insert(ids[0], 0, address(0), address(0)); + bool result = proxy.execute(address(fixture)); + assertTrue(!result, "did not revert"); + } +} diff --git a/src/test/unit/TestSortedDoublyLLRemove.sol b/src/test/unit/TestSortedDoublyLLRemove.sol new file mode 100644 index 00000000..e9f91e95 --- /dev/null +++ b/src/test/unit/TestSortedDoublyLLRemove.sol @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "ds-test/test.sol"; +import "../interfaces/ICheatCodes.sol"; +import "contracts/test/mocks/SortedDoublyLLFixture.sol"; +import "contracts/test/helpers/RevertProxy.sol"; + +contract TestSortedDoublyLLRemove is DSTest { + ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); + + address[] ids = [address(1), address(2), address(3), address(4), address(5), address(6)]; + uint256[] keys = [uint256(13), uint256(11), uint256(9), uint256(7), uint256(5), uint256(3)]; + + SortedDoublyLLFixture fixture; + RevertProxy proxy; + + function setUp() public { + proxy = new RevertProxy(); + fixture = new SortedDoublyLLFixture(); + fixture.setMaxSize(10); + } + + function testRemove() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + + fixture.remove(ids[1]); + + assertTrue(!fixture.contains(ids[1]), "should not contain node"); + assertEq(fixture.getSize(), 2, "wrong size"); + assertEq(fixture.getNext(ids[0]), ids[2], "wrong next"); + assertEq(fixture.getPrev(ids[2]), ids[0], "wrong prev"); + } + + function testRemoveSingleNode() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + + fixture.remove(ids[0]); + + assertTrue(!fixture.contains(ids[0]), "should not contain node"); + assertEq(fixture.getSize(), 0, "wrong size"); + assertEq(fixture.getFirst(), address(0), "wrong head"); + assertEq(fixture.getLast(), address(0), "wrong tail"); + } + + function testRemoveHead() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + + fixture.remove(ids[0]); + + assertTrue(!fixture.contains(ids[0]), "should not contain node"); + assertEq(fixture.getSize(), 1, "wrong size"); + assertEq(fixture.getFirst(), ids[1], "wrong head"); + assertEq(fixture.getPrev(ids[1]), address(0), "wrong prev"); + } + + function testRemoveTail() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + + fixture.remove(ids[1]); + + assertTrue(!fixture.contains(ids[1]), "should not contain node"); + assertEq(fixture.getSize(), 1, "wrong size"); + assertEq(fixture.getLast(), ids[0], "wrong prev"); + assertEq(fixture.getNext(ids[0]), address(0), "wrong next"); + } + + function testRemoveNotInList() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + + SortedDoublyLLFixture(address(proxy)).remove(ids[1]); + bool result = proxy.execute(address(fixture)); + assertTrue(!result, "did not revert"); + } +} diff --git a/src/test/unit/TestSortedDoublyLLUpdateKey.sol b/src/test/unit/TestSortedDoublyLLUpdateKey.sol new file mode 100644 index 00000000..e2b3cb1c --- /dev/null +++ b/src/test/unit/TestSortedDoublyLLUpdateKey.sol @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.9; + +import "ds-test/test.sol"; +import "../interfaces/ICheatCodes.sol"; +import "contracts/test/mocks/SortedDoublyLLFixture.sol"; +import "contracts/test/helpers/RevertProxy.sol"; + +contract TestSortedDoublyLLUpdateKey is DSTest { + ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); + + address[] ids = [address(1), address(2), address(3), address(4), address(5), address(6)]; + uint256[] keys = [uint256(13), uint256(11), uint256(9), uint256(7), uint256(5), uint256(3)]; + + SortedDoublyLLFixture fixture; + RevertProxy proxy; + + function setUp() public { + proxy = new RevertProxy(); + fixture = new SortedDoublyLLFixture(); + fixture.setMaxSize(10); + } + + function testUpdateKeyMissingId() public { + SortedDoublyLLFixture(address(proxy)).updateKey(ids[3], 5, address(0), address(0)); + bool result = proxy.execute(address(fixture)); + assertTrue(!result, "did not revert"); + } + + function testUpdateKeyIncreaseNoHint() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[3], keys[3], ids[2], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + uint256 newKey = keys[3] + 3; + fixture.updateKey(ids[3], newKey, address(0), address(0)); + assertEq(fixture.getKey(ids[3]), newKey, "wrong key"); + assertEq(fixture.getNext(ids[3]), ids[2], "wrong next"); + assertEq(fixture.getPrev(ids[3]), ids[1], "wrong prev"); + assertEq(fixture.getNext(ids[1]), ids[3], "wrong next"); + assertEq(fixture.getPrev(ids[2]), ids[3], "wrong prev"); + } + + function testUpdateKeyDecreaseNoHint() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + fixture.insert(ids[3], keys[3], ids[2], address(0)); + fixture.insert(ids[4], keys[4], ids[3], address(0)); + fixture.insert(ids[5], keys[5], ids[4], address(0)); + + uint256 newKey = keys[3] - 3; + fixture.updateKey(ids[3], newKey, address(0), address(0)); + assertEq(fixture.getKey(ids[3]), newKey, "wrong key"); + assertEq(fixture.getNext(ids[3]), ids[5], "wrong next"); + assertEq(fixture.getPrev(ids[3]), ids[4], "wrong prev"); + assertEq(fixture.getNext(ids[4]), ids[3], "wrong next"); + assertEq(fixture.getPrev(ids[5]), ids[3], "wrong prev"); + } + + function testUpdateKeyZeroNewKey() public { + fixture.insert(ids[0], keys[0], address(0), address(0)); + fixture.insert(ids[1], keys[1], ids[0], address(0)); + fixture.insert(ids[2], keys[2], ids[1], address(0)); + + uint256 newKey = 10; + fixture.updateKey(ids[2], newKey, address(0), address(0)); + assertTrue(fixture.contains(ids[2]), "list should not contain id after updating with newKey = 0"); + } +} From 467a4011f4a4111b0af4d5ef43700e54b4b76b68 Mon Sep 17 00:00:00 2001 From: RiccardoBiosas Date: Tue, 12 Jul 2022 15:21:43 -0500 Subject: [PATCH 2/5] tests(truffle): delete all truffle-based solidity tests --- contracts/test/TestEarningsPool.sol | 29 ---- contracts/test/TestEarningsPoolLIP36.sol | 68 -------- contracts/test/TestMathUtils.sol | 29 ---- contracts/test/TestMathUtilsV2.sol | 30 ---- contracts/test/TestPreciseMathUtils.sol | 42 ----- .../test/TestSortedDoublyLLFindWithHints.sol | 148 ------------------ .../test/TestSortedDoublyLLFindWithHints2.sol | 123 --------------- contracts/test/TestSortedDoublyLLInsert.sol | 112 ------------- contracts/test/TestSortedDoublyLLRemove.sol | 75 --------- .../test/TestSortedDoublyLLUpdateKey.sol | 73 --------- 10 files changed, 729 deletions(-) delete mode 100644 contracts/test/TestEarningsPool.sol delete mode 100644 contracts/test/TestEarningsPoolLIP36.sol delete mode 100644 contracts/test/TestMathUtils.sol delete mode 100644 contracts/test/TestMathUtilsV2.sol delete mode 100644 contracts/test/TestPreciseMathUtils.sol delete mode 100644 contracts/test/TestSortedDoublyLLFindWithHints.sol delete mode 100644 contracts/test/TestSortedDoublyLLFindWithHints2.sol delete mode 100644 contracts/test/TestSortedDoublyLLInsert.sol delete mode 100644 contracts/test/TestSortedDoublyLLRemove.sol delete mode 100644 contracts/test/TestSortedDoublyLLUpdateKey.sol diff --git a/contracts/test/TestEarningsPool.sol b/contracts/test/TestEarningsPool.sol deleted file mode 100644 index 7030abc2..00000000 --- a/contracts/test/TestEarningsPool.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "./mocks/EarningsPoolFixture.sol"; -import "./helpers/truffle/Assert.sol"; - -contract TestEarningsPool { - EarningsPoolFixture fixture; - - function beforeEach() public { - fixture = new EarningsPoolFixture(); - fixture.setStake(1000); - fixture.setCommission(500000, 500000); - } - - function test_setCommission() public { - fixture.setCommission(5, 10); - uint256 transcoderRewardCut = fixture.getTranscoderRewardCut(); - uint256 transcoderFeeShare = fixture.getTranscoderFeeShare(); - Assert.equal(transcoderRewardCut, 5, "wrong transcoderRewardCut"); - Assert.equal(transcoderFeeShare, 10, "wrong transcoderFeeShare"); - } - - function test_setStake() public { - fixture.setStake(5000); - uint256 totalStake = fixture.getTotalStake(); - Assert.equal(totalStake, 5000, "wrong totalStake"); - } -} diff --git a/contracts/test/TestEarningsPoolLIP36.sol b/contracts/test/TestEarningsPoolLIP36.sol deleted file mode 100644 index 38704b6a..00000000 --- a/contracts/test/TestEarningsPoolLIP36.sol +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "./mocks/EarningsPoolFixture.sol"; -import "./helpers/truffle/Assert.sol"; -import "../libraries/PreciseMathUtils.sol"; - -contract TestEarningsPoolLIP36 { - EarningsPoolFixture fixture; - - function beforeEach() public { - fixture = new EarningsPoolFixture(); - fixture.setStake(1000); - fixture.setCommission(500000, 500000); - } - - function test_updateCumulativeFeeFactor_no_prevEarningsPool() public { - uint256 fees = 1000; - - // earningsPool.cumulativeFeeFactor == 0 - // prevEarningsPool.cumulativeFeeFactor == 0 - // prevEarningsPool.cumulativeRewardFactor == 0 - fixture.updateCumulativeFeeFactor(fees); - uint256 expFeeFactor = PreciseMathUtils.percPoints(fees, fixture.getTotalStake()); - Assert.equal(fixture.getCumulativeFeeFactor(), expFeeFactor, "should set cumulativeFeeFactor"); - - // earningsPool.cumulativeFeeFactor != 0 - fixture.updateCumulativeFeeFactor(fees); - expFeeFactor += PreciseMathUtils.percPoints(fees, fixture.getTotalStake()); - Assert.equal(fixture.getCumulativeFeeFactor(), expFeeFactor, "should update cumulativeFeeFactor"); - } - - function test_updateCumulativeFeeFactor_prevEarningsPool() public { - uint256 fees = 200; - - // prevEarningsPool.cumulativeFeeFactor = 2 - // prevEarningsPool.cumulativeRewardFactor = 3 - uint256 prevFeeFactor = 2; - uint256 prevRewFactor = 3; - fixture.setPrevPoolEarningsFactors(prevFeeFactor, prevRewFactor); - - // earningsPool.cumulativeFeeFactor == 0 - fixture.updateCumulativeFeeFactor(fees); - uint256 expFeeFactor = prevFeeFactor + PreciseMathUtils.percOf(prevRewFactor, fees, fixture.getTotalStake()); - Assert.equal(fixture.getCumulativeFeeFactor(), expFeeFactor, "should update cumulativeFeeFactor"); - - // earningsPool.cumulativeFeeFactor != 0 - fixture.updateCumulativeFeeFactor(fees); - expFeeFactor += PreciseMathUtils.percOf(prevRewFactor, fees, fixture.getTotalStake()); - } - - function test_updateCumulativeRewardFactor() public { - uint256 rewards = 1000; - - // prevEarningsPool.cumulativeRewardFactor == 0 - uint256 expRewardFactor = PreciseMathUtils.percPoints(1, 1) + - PreciseMathUtils.percOf(PreciseMathUtils.percPoints(1, 1), rewards, fixture.getTotalStake()); - - fixture.updateCumulativeRewardFactor(1000); - Assert.equal(expRewardFactor, fixture.getCumulativeRewardFactor(), "incorrect cumulative reward factor"); - - // prevEarningsPool.cumulativeRewardFactor != 0 - fixture.setPrevPoolEarningsFactors(0, expRewardFactor); - expRewardFactor += PreciseMathUtils.percOf(expRewardFactor, rewards, fixture.getTotalStake()); - fixture.updateCumulativeRewardFactor(1000); - Assert.equal(expRewardFactor, fixture.getCumulativeRewardFactor(), "incorrect cumulative reward factor"); - } -} diff --git a/contracts/test/TestMathUtils.sol b/contracts/test/TestMathUtils.sol deleted file mode 100644 index cceda3ff..00000000 --- a/contracts/test/TestMathUtils.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "../libraries/MathUtils.sol"; -import "./helpers/truffle/Assert.sol"; - -contract TestMathUtils { - function test_validPerc() public { - Assert.equal(MathUtils.validPerc(50), true, "50 should be a valid percentage"); - Assert.equal(MathUtils.validPerc(0), true, "0 should be a valid percentage"); - Assert.equal(MathUtils.validPerc(1000000), true, "the max should be a valid percentage"); - Assert.equal(MathUtils.validPerc(1000001), false, "1 more than the max should not be valid percentage"); - } - - function test_percOf1() public { - Assert.equal(MathUtils.percOf(100, 3, 4), 75, "3/4 of 100 should be 75"); - Assert.equal(MathUtils.percOf(100, 7, 9), 77, "7/9 of 100 should be 77"); - } - - function test_percOf2() public { - Assert.equal(MathUtils.percOf(100, 3), 0, ".0003% of 100 is 0"); - Assert.equal(MathUtils.percOf(100, 100000), 10, "10% of 100 is 10"); - } - - function test_percPoints() public { - Assert.equal(MathUtils.percPoints(3, 4), 750000, "3/4 should convert to valid percentage"); - Assert.equal(MathUtils.percPoints(100, 300), 333333, "100/300 should convert to valid percentage"); - } -} diff --git a/contracts/test/TestMathUtilsV2.sol b/contracts/test/TestMathUtilsV2.sol deleted file mode 100644 index 71c40864..00000000 --- a/contracts/test/TestMathUtilsV2.sol +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "../libraries/MathUtilsV2.sol"; -import "./helpers/truffle/Assert.sol"; - -contract TestMathUtilsV2 { - function test_validPerc() public { - Assert.equal(MathUtils.validPerc(50), true, "50 should be a valid percentage"); - Assert.equal(MathUtils.validPerc(0), true, "0 should be a valid percentage"); - Assert.equal(MathUtils.validPerc(1000000000), true, "the max should be a valid percentage"); - Assert.equal(MathUtils.validPerc(1000000001), false, "1 more than the max should not be valid percentage"); - } - - function test_percOf1() public { - Assert.equal(MathUtils.percOf(100, 3, 4), 75, "3/4 of 100 should be 75"); - Assert.equal(MathUtils.percOf(100, 7, 9), 77, "7/9 of 100 should be 77"); - } - - function test_percOf2() public { - Assert.equal(MathUtils.percOf(100, 3), 0, ".0000003% of 100 is 0"); - Assert.equal(MathUtils.percOf(1000000000, 1), 1, ".0000001% of 1000000000 is 1"); - Assert.equal(MathUtils.percOf(100, 100000000), 10, "10% of 100 is 10"); - } - - function test_percPoints() public { - Assert.equal(MathUtils.percPoints(3, 4), 750000000, "3/4 should convert to valid percentage"); - Assert.equal(MathUtils.percPoints(100, 300), 333333333, "100/300 should convert to valid percentage"); - } -} diff --git a/contracts/test/TestPreciseMathUtils.sol b/contracts/test/TestPreciseMathUtils.sol deleted file mode 100644 index 16bde99b..00000000 --- a/contracts/test/TestPreciseMathUtils.sol +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "../libraries/PreciseMathUtils.sol"; -import "./helpers/truffle/Assert.sol"; - -contract TestPreciseMathUtils { - function test_validPerc() public { - Assert.equal(PreciseMathUtils.validPerc(50), true, "50 should be a valid percentage"); - Assert.equal(PreciseMathUtils.validPerc(0), true, "0 should be a valid percentage"); - Assert.equal(PreciseMathUtils.validPerc(10**27), true, "the max should be a valid percentage"); - Assert.equal( - PreciseMathUtils.validPerc(10**27 + 1), - false, - "1 more than the max should not be valid percentage" - ); - } - - function test_percOf1() public { - Assert.equal(PreciseMathUtils.percOf(100, 3, 4), 75, "3/4 of 100 should be 75"); - Assert.equal(PreciseMathUtils.percOf(100, 7, 9), 77, "7/9 of 100 should be 77"); - } - - function test_percOf2() public { - Assert.equal(PreciseMathUtils.percOf(100, 3), 0, ".0000000000000000000000003% of 100 is 0"); - Assert.equal(PreciseMathUtils.percOf(10**27, 1), 1, ".0000000000000000000000001% of 1000000000 is 1"); - Assert.equal(PreciseMathUtils.percOf(100, 10**27 / 10), 10, "10% of 100 is 10"); - } - - function test_percPoints() public { - Assert.equal( - PreciseMathUtils.percPoints(3, 4), - 750000000000000000000000000, - "3/4 should convert to valid percentage" - ); - Assert.equal( - PreciseMathUtils.percPoints(100, 300), - 333333333333333333333333333, - "100/300 should convert to valid percentage" - ); - } -} diff --git a/contracts/test/TestSortedDoublyLLFindWithHints.sol b/contracts/test/TestSortedDoublyLLFindWithHints.sol deleted file mode 100644 index 5e5967b9..00000000 --- a/contracts/test/TestSortedDoublyLLFindWithHints.sol +++ /dev/null @@ -1,148 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "./mocks/SortedDoublyLLFixture.sol"; -import "./helpers/truffle/Assert.sol"; - -contract TestSortedDoublyLLFindWithHints { - address[] ids = [address(1), address(2), address(3), address(4), address(5), address(6)]; - uint256[] keys = [uint256(13), uint256(11), uint256(9), uint256(7), uint256(5), uint256(3)]; - - SortedDoublyLLFixture fixture; - - function beforeEach() public { - fixture = new SortedDoublyLLFixture(); - fixture.setMaxSize(10); - } - - function test_insert_findNoHintUpdateHead() public { - fixture.insert(ids[1], keys[1], address(0), address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[3], keys[3], ids[2], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.insert(ids[0], keys[0], address(0), address(0)); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getFirst(), ids[0], "wrong head"); - Assert.equal(fixture.getKey(ids[0]), keys[0], "wrong key"); - Assert.equal(fixture.getNext(ids[0]), ids[1], "wrong next"); - Assert.equal(fixture.getPrev(ids[0]), address(0), "wrong prev"); - } - - function test_insert_findNoHintUpdateTail() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[3], keys[3], ids[2], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - - fixture.insert(ids[5], keys[5], address(0), address(0)); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getLast(), ids[5], "wrong tail"); - Assert.equal(fixture.getKey(ids[5]), keys[5], "wrong key"); - Assert.equal(fixture.getNext(ids[5]), address(0), "wrong next transcoder"); - Assert.equal(fixture.getPrev(ids[5]), ids[4], "wrong prev transcoder"); - } - - function test_insert_findNoHintAtPosition() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[3], keys[3], ids[1], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.insert(ids[2], keys[2], address(0), address(0)); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getKey(ids[2]), keys[2], "wrong"); - Assert.equal(fixture.getNext(ids[2]), ids[3], "wrong next"); - Assert.equal(fixture.getPrev(ids[2]), ids[1], "wrong prev"); - } - - function test_insert_findWithHintNextUpdateHead() public { - fixture.insert(ids[1], keys[1], address(0), address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[3], keys[3], ids[2], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.insert(ids[0], keys[0], address(0), ids[2]); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getFirst(), ids[0], "wrong head"); - Assert.equal(fixture.getKey(ids[0]), keys[0], "wrong key"); - Assert.equal(fixture.getNext(ids[0]), ids[1], "wrong next"); - Assert.equal(fixture.getPrev(ids[0]), address(0), "wrong prev"); - } - - function test_insert_findWithHintNextUpdateTail() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[3], keys[3], ids[2], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.insert(ids[1], 3, address(0), ids[5]); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getLast(), ids[1], "wrong tail"); - Assert.equal(fixture.getKey(ids[1]), 3, "wrong key"); - Assert.equal(fixture.getNext(ids[1]), address(0), "wrong next"); - Assert.equal(fixture.getPrev(ids[1]), ids[5], "wrong prev"); - } - - function test_insert_findWithHintNextAtPosition() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[3], keys[3], ids[1], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.insert(ids[2], keys[2], address(0), ids[3]); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getKey(ids[2]), keys[2], "wrong key"); - Assert.equal(fixture.getNext(ids[2]), ids[3], "wrong next"); - Assert.equal(fixture.getPrev(ids[2]), ids[1], "wrong prev"); - } - - function test_insert_findWithHintPrevUpdateTail() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[3], keys[3], ids[1], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - - fixture.insert(ids[5], keys[5], ids[1], address(0)); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getLast(), ids[5], "wrong tail"); - Assert.equal(fixture.getKey(ids[5]), keys[5], "wrong key"); - Assert.equal(fixture.getNext(ids[5]), address(0), "wrong next"); - Assert.equal(fixture.getPrev(ids[5]), ids[4], "wrong prev"); - } - - function test_insert_findWithHintPrevAtPosition() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[3], keys[3], ids[1], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.insert(ids[2], keys[2], ids[0], address(0)); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getKey(ids[2]), keys[2], "wrong key"); - Assert.equal(fixture.getNext(ids[2]), ids[3], "wrong next"); - Assert.equal(fixture.getPrev(ids[2]), ids[1], "wrong prev"); - } - - function test_insert_findWithHint() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[4], keys[4], ids[2], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.insert(ids[3], keys[3], ids[2], ids[4]); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getKey(ids[3]), keys[3], "wrong key"); - Assert.equal(fixture.getNext(ids[3]), ids[4], "wrong next"); - Assert.equal(fixture.getPrev(ids[3]), ids[2], "wrong prev"); - } -} diff --git a/contracts/test/TestSortedDoublyLLFindWithHints2.sol b/contracts/test/TestSortedDoublyLLFindWithHints2.sol deleted file mode 100644 index e3a88e85..00000000 --- a/contracts/test/TestSortedDoublyLLFindWithHints2.sol +++ /dev/null @@ -1,123 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "./mocks/SortedDoublyLLFixture.sol"; -import "./helpers/truffle/Assert.sol"; - -contract TestSortedDoublyLLFindWithHints2 { - address[] ids = [address(1), address(2), address(3), address(4), address(5), address(6)]; - uint256[] keys = [uint256(13), uint256(11), uint256(9), uint256(7), uint256(5), uint256(3)]; - - SortedDoublyLLFixture fixture; - - function beforeEach() public { - fixture = new SortedDoublyLLFixture(); - fixture.setMaxSize(10); - } - - function test_insert_findWithHintPrevRemoved() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[4], keys[4], ids[2], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.remove(ids[2]); - fixture.insert(ids[3], keys[3], ids[2], ids[4]); - Assert.equal(fixture.getSize(), 5, "wrong size"); - Assert.equal(fixture.getKey(ids[3]), keys[3], "wrong key"); - Assert.equal(fixture.getNext(ids[3]), ids[4], "wrong next"); - Assert.equal(fixture.getPrev(ids[3]), ids[1], "wrong prev"); - } - - function test_insert_findWithHintPrevRemovedUpdateHead() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[3], keys[3], ids[2], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.remove(ids[0]); - fixture.insert(ids[1], keys[1], ids[0], ids[2]); - Assert.equal(fixture.getSize(), 5, "wrong size"); - Assert.equal(fixture.getFirst(), ids[1], "wrong head"); - Assert.equal(fixture.getKey(ids[1]), keys[1], "wrong key"); - Assert.equal(fixture.getNext(ids[1]), ids[2], "wrong next"); - Assert.equal(fixture.getPrev(ids[1]), address(0), "wrong prev"); - } - - function test_insert_findWithHintPrevDecreased() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[4], keys[4], ids[2], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.updateKey(ids[2], 6, address(0), address(0)); - fixture.insert(ids[3], keys[3], ids[2], ids[4]); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getKey(ids[3]), keys[3], "wrong key"); - Assert.equal(fixture.getNext(ids[3]), ids[2], "wrong next"); - Assert.equal(fixture.getPrev(ids[3]), ids[1], "wrong prev"); - } - - function test_insert_findWithHintNextRemoved() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[4], keys[4], ids[2], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.remove(ids[4]); - fixture.insert(ids[3], keys[3], ids[2], ids[4]); - Assert.equal(fixture.getSize(), 5, "wrong size"); - Assert.equal(fixture.getKey(ids[3]), keys[3], "wrong key"); - Assert.equal(fixture.getNext(ids[3]), ids[5], "wrong next"); - Assert.equal(fixture.getPrev(ids[3]), ids[2], "wrong prev"); - } - - function test_insert_findWithHintNextRemovedUpdateTail() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[3], keys[3], ids[2], address(0)); - fixture.insert(ids[5], keys[5], ids[3], address(0)); - - fixture.remove(ids[5]); - fixture.insert(ids[4], keys[4], ids[3], ids[5]); - Assert.equal(fixture.getSize(), 5, "wrong size"); - Assert.equal(fixture.getLast(), ids[4], "wrong tail"); - Assert.equal(fixture.getKey(ids[4]), keys[4], "wrong key"); - Assert.equal(fixture.getNext(ids[4]), address(0), "wrong next"); - Assert.equal(fixture.getPrev(ids[4]), ids[3], "wrong prev"); - } - - function test_insert_findWithHintNextIncreased() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[4], keys[4], ids[2], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.updateKey(ids[4], 8, address(0), address(0)); - fixture.insert(ids[3], keys[3], ids[2], ids[4]); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getKey(ids[3]), keys[3], "wrong key"); - Assert.equal(fixture.getNext(ids[3]), ids[5], "wrong next"); - Assert.equal(fixture.getPrev(ids[3]), ids[4], "wrong prev"); - } - - function test_insert_findWithHintNotTightBound() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[4], keys[4], ids[2], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - fixture.insert(ids[3], keys[3], ids[0], ids[5]); - Assert.equal(fixture.getSize(), 6, "wrong size"); - Assert.equal(fixture.getKey(ids[3]), keys[3], "wrong key"); - Assert.equal(fixture.getNext(ids[3]), ids[4], "wrong next"); - Assert.equal(fixture.getPrev(ids[3]), ids[2], "wrong prev"); - } -} diff --git a/contracts/test/TestSortedDoublyLLInsert.sol b/contracts/test/TestSortedDoublyLLInsert.sol deleted file mode 100644 index bcfc84bb..00000000 --- a/contracts/test/TestSortedDoublyLLInsert.sol +++ /dev/null @@ -1,112 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "./mocks/SortedDoublyLLFixture.sol"; -import "./helpers/RevertProxy.sol"; -import "./helpers/truffle/Assert.sol"; - -contract TestSortedDoublyLLInsert { - address[] ids = [address(1), address(2), address(3), address(4), address(5), address(6)]; - uint256[] keys = [uint256(13), uint256(11), uint256(9), uint256(7), uint256(5), uint256(5), uint256(3)]; - - SortedDoublyLLFixture fixture; - RevertProxy proxy; - - function beforeAll() public { - proxy = new RevertProxy(); - } - - function beforeEach() public { - fixture = new SortedDoublyLLFixture(); - fixture.setMaxSize(3); - } - - function test_setMaxSize() public { - Assert.equal(fixture.getMaxSize(), 3, "wrong max size"); - } - - function test_setMaxSize_update() public { - fixture.setMaxSize(10); - - Assert.equal(fixture.getMaxSize(), 10, "wrong max size"); - } - - function test_setMaxSize_decreaseSize() public { - SortedDoublyLLFixture(address(proxy)).setMaxSize(1); - bool result = proxy.execute(address(fixture)); - Assert.isFalse(result, "did not revert"); - } - - function test_insert_empty() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - Assert.equal(fixture.getSize(), 1, "wrong size"); - Assert.equal(fixture.getFirst(), ids[0], "wrong head"); - Assert.equal(fixture.getLast(), ids[0], "wrong tail"); - Assert.equal(fixture.getKey(ids[0]), keys[0], "wrong key"); - Assert.equal(fixture.getNext(ids[0]), address(0), "wrong next"); - Assert.equal(fixture.getPrev(ids[0]), address(0), "wrong prev"); - } - - function test_insert_updateHead() public { - fixture.insert(ids[1], keys[1], address(0), address(0)); - - fixture.insert(ids[0], keys[0], address(0), ids[1]); - Assert.equal(fixture.getSize(), 2, "wrong size"); - Assert.equal(fixture.getFirst(), ids[0], "wrong head"); - Assert.equal(fixture.getKey(ids[0]), keys[0], "wrong key"); - Assert.equal(fixture.getNext(ids[0]), ids[1], "wrong next"); - Assert.equal(fixture.getPrev(ids[0]), address(0), "wrong prev"); - } - - function test_insert_updateTail() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - - fixture.insert(ids[1], keys[1], ids[0], address(0)); - Assert.equal(fixture.getSize(), 2, "wrong size"); - Assert.equal(fixture.getLast(), ids[1], "wrong tail"); - Assert.equal(fixture.getKey(ids[1]), keys[1], "wrong key"); - Assert.equal(fixture.getNext(ids[1]), address(0), "wrong next"); - Assert.equal(fixture.getPrev(ids[1]), ids[0], "wrong prev"); - } - - function test_insert_atPosition() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[2], keys[2], ids[0], address(0)); - - fixture.insert(ids[1], keys[1], ids[0], ids[2]); - Assert.equal(fixture.getSize(), 3, "wrong size"); - Assert.equal(fixture.getKey(ids[1]), keys[1], "wrong stake"); - Assert.equal(fixture.getNext(ids[1]), ids[2], "wrong next transcoder"); - Assert.equal(fixture.getPrev(ids[1]), ids[0], "wrong prev transcoder"); - } - - function test_insert_full() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - - SortedDoublyLLFixture(address(proxy)).insert(ids[3], keys[3], address(0), address(0)); - bool result = proxy.execute(address(fixture)); - Assert.isFalse(result, "did not revert"); - } - - function test_insert_containsId() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - - SortedDoublyLLFixture(address(proxy)).insert(ids[0], keys[0], address(0), address(0)); - bool result = proxy.execute(address(fixture)); - Assert.isFalse(result, "did not revert"); - } - - function test_insert_null() public { - SortedDoublyLLFixture(address(proxy)).insert(address(0), keys[0], address(0), address(0)); - bool result = proxy.execute(address(fixture)); - Assert.isFalse(result, "did not revert"); - } - - function test_insert_zeroKey() public { - SortedDoublyLLFixture(address(proxy)).insert(ids[0], 0, address(0), address(0)); - bool result = proxy.execute(address(fixture)); - Assert.isFalse(result, "did not revert"); - } -} diff --git a/contracts/test/TestSortedDoublyLLRemove.sol b/contracts/test/TestSortedDoublyLLRemove.sol deleted file mode 100644 index 8d34ab7d..00000000 --- a/contracts/test/TestSortedDoublyLLRemove.sol +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "./mocks/SortedDoublyLLFixture.sol"; -import "./helpers/RevertProxy.sol"; -import "./helpers/truffle/Assert.sol"; - -contract TestSortedDoublyLLRemove { - address[] ids = [address(1), address(2), address(3), address(4), address(5), address(6)]; - uint256[] keys = [uint256(13), uint256(11), uint256(9), uint256(7), uint256(5), uint256(3)]; - - SortedDoublyLLFixture fixture; - RevertProxy proxy; - - function beforeAll() public { - proxy = new RevertProxy(); - } - - function beforeEach() public { - fixture = new SortedDoublyLLFixture(); - fixture.setMaxSize(10); - } - - function test_remove() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - - fixture.remove(ids[1]); - Assert.equal(fixture.contains(ids[1]), false, "should not contain node"); - Assert.equal(fixture.getSize(), 2, "wrong size"); - Assert.equal(fixture.getNext(ids[0]), ids[2], "wrong next"); - Assert.equal(fixture.getPrev(ids[2]), ids[0], "wrong prev"); - } - - function test_remove_singleNode() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - - fixture.remove(ids[0]); - Assert.equal(fixture.contains(ids[0]), false, "should not contain node"); - Assert.equal(fixture.getSize(), 0, "wrong size"); - Assert.equal(fixture.getFirst(), address(0), "wrong head"); - Assert.equal(fixture.getLast(), address(0), "wrong tail"); - } - - function test_remove_head() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - - fixture.remove(ids[0]); - Assert.equal(fixture.contains(ids[0]), false, "should not contain node"); - Assert.equal(fixture.getSize(), 1, "wrong size"); - Assert.equal(fixture.getFirst(), ids[1], "wrong head"); - Assert.equal(fixture.getPrev(ids[1]), address(0), "wrong prev"); - } - - function test_remove_tail() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - - fixture.remove(ids[1]); - Assert.equal(fixture.contains(ids[1]), false, "should not contain node"); - Assert.equal(fixture.getSize(), 1, "wrong size"); - Assert.equal(fixture.getLast(), ids[0], "wrong prev"); - Assert.equal(fixture.getNext(ids[0]), address(0), "wrong next"); - } - - function test_remove_notInList() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - - SortedDoublyLLFixture(address(proxy)).remove(ids[1]); - bool result = proxy.execute(address(fixture)); - Assert.isFalse(result, "did not revert"); - } -} diff --git a/contracts/test/TestSortedDoublyLLUpdateKey.sol b/contracts/test/TestSortedDoublyLLUpdateKey.sol deleted file mode 100644 index 988f4aa9..00000000 --- a/contracts/test/TestSortedDoublyLLUpdateKey.sol +++ /dev/null @@ -1,73 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "./mocks/SortedDoublyLLFixture.sol"; -import "./helpers/RevertProxy.sol"; -import "./helpers/truffle/Assert.sol"; - -contract TestSortedDoublyLLUpdateKey { - address[] ids = [address(1), address(2), address(3), address(4), address(5), address(6)]; - uint256[] keys = [uint256(13), uint256(11), uint256(9), uint256(7), uint256(5), uint256(3)]; - - SortedDoublyLLFixture fixture; - RevertProxy proxy; - - function beforeAll() public { - proxy = new RevertProxy(); - } - - function beforeEach() public { - fixture = new SortedDoublyLLFixture(); - fixture.setMaxSize(10); - } - - function test_updateKey_missingId() public { - SortedDoublyLLFixture(address(proxy)).updateKey(ids[3], 5, address(0), address(0)); - bool result = proxy.execute(address(fixture)); - Assert.isFalse(result, "did not revert"); - } - - function test_updateKey_increaseNoHint() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[3], keys[3], ids[2], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - uint256 newKey = keys[3] + 3; - fixture.updateKey(ids[3], newKey, address(0), address(0)); - Assert.equal(fixture.getKey(ids[3]), newKey, "wrong key"); - Assert.equal(fixture.getNext(ids[3]), ids[2], "wrong next"); - Assert.equal(fixture.getPrev(ids[3]), ids[1], "wrong prev"); - Assert.equal(fixture.getNext(ids[1]), ids[3], "wrong next"); - Assert.equal(fixture.getPrev(ids[2]), ids[3], "wrong prev"); - } - - function test_updateKey_decreaseNoHint() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - fixture.insert(ids[3], keys[3], ids[2], address(0)); - fixture.insert(ids[4], keys[4], ids[3], address(0)); - fixture.insert(ids[5], keys[5], ids[4], address(0)); - - uint256 newKey = keys[3] - 3; - fixture.updateKey(ids[3], newKey, address(0), address(0)); - Assert.equal(fixture.getKey(ids[3]), newKey, "wrong key"); - Assert.equal(fixture.getNext(ids[3]), ids[5], "wrong next"); - Assert.equal(fixture.getPrev(ids[3]), ids[4], "wrong prev"); - Assert.equal(fixture.getNext(ids[4]), ids[3], "wrong next"); - Assert.equal(fixture.getPrev(ids[5]), ids[3], "wrong prev"); - } - - function test_updateKey_zeroNewKey() public { - fixture.insert(ids[0], keys[0], address(0), address(0)); - fixture.insert(ids[1], keys[1], ids[0], address(0)); - fixture.insert(ids[2], keys[2], ids[1], address(0)); - - uint256 newKey = 0; - fixture.updateKey(ids[2], newKey, address(0), address(0)); - Assert.isFalse(fixture.contains(ids[2]), "list should not contain id after updating with newKey = 0"); - } -} From 6a78c544c48c99ce7e6a0258816a3f8d07d89bdd Mon Sep 17 00:00:00 2001 From: RiccardoBiosas Date: Tue, 12 Jul 2022 15:32:29 -0500 Subject: [PATCH 3/5] tests(hardhat): removed runSolidityTests script and related dependencies --- test/unit/EarningsPool.js | 4 -- test/unit/MathUtils.js | 3 - test/unit/MathUtilsV2.js | 3 - test/unit/PreciseMathUtils.js | 3 - test/unit/SortedDoublyLL.js | 30 -------- test/unit/helpers/runSolidityTest.js | 102 --------------------------- 6 files changed, 145 deletions(-) delete mode 100644 test/unit/EarningsPool.js delete mode 100644 test/unit/MathUtils.js delete mode 100644 test/unit/MathUtilsV2.js delete mode 100644 test/unit/PreciseMathUtils.js delete mode 100644 test/unit/SortedDoublyLL.js delete mode 100644 test/unit/helpers/runSolidityTest.js diff --git a/test/unit/EarningsPool.js b/test/unit/EarningsPool.js deleted file mode 100644 index c70a3bad..00000000 --- a/test/unit/EarningsPool.js +++ /dev/null @@ -1,4 +0,0 @@ -import runSolidityTest from "./helpers/runSolidityTest" - -runSolidityTest("TestEarningsPool", ["AssertUint"]) -runSolidityTest("TestEarningsPoolLIP36", ["AssertUint"]) diff --git a/test/unit/MathUtils.js b/test/unit/MathUtils.js deleted file mode 100644 index 0b34092e..00000000 --- a/test/unit/MathUtils.js +++ /dev/null @@ -1,3 +0,0 @@ -import runSolidityTest from "./helpers/runSolidityTest" - -runSolidityTest("TestMathUtils", ["AssertBool", "AssertUint"]) diff --git a/test/unit/MathUtilsV2.js b/test/unit/MathUtilsV2.js deleted file mode 100644 index 7b3d9769..00000000 --- a/test/unit/MathUtilsV2.js +++ /dev/null @@ -1,3 +0,0 @@ -import runSolidityTest from "./helpers/runSolidityTest" - -runSolidityTest("TestMathUtilsV2", ["AssertBool", "AssertUint"]) diff --git a/test/unit/PreciseMathUtils.js b/test/unit/PreciseMathUtils.js deleted file mode 100644 index 041a3445..00000000 --- a/test/unit/PreciseMathUtils.js +++ /dev/null @@ -1,3 +0,0 @@ -import runSolidityTest from "./helpers/runSolidityTest" - -runSolidityTest("TestPreciseMathUtils", ["AssertBool", "AssertUint"]) diff --git a/test/unit/SortedDoublyLL.js b/test/unit/SortedDoublyLL.js deleted file mode 100644 index f52469bf..00000000 --- a/test/unit/SortedDoublyLL.js +++ /dev/null @@ -1,30 +0,0 @@ -import runSolidityTest from "./helpers/runSolidityTest" - -runSolidityTest("TestSortedDoublyLLFindWithHints", [ - "SortedDoublyLL", - "AssertAddress", - "AssertUint" -]) -runSolidityTest("TestSortedDoublyLLFindWithHints2", [ - "SortedDoublyLL", - "AssertAddress", - "AssertUint" -]) -runSolidityTest("TestSortedDoublyLLInsert", [ - "SortedDoublyLL", - "AssertAddress", - "AssertUint", - "AssertBool" -]) -runSolidityTest("TestSortedDoublyLLRemove", [ - "SortedDoublyLL", - "AssertAddress", - "AssertUint", - "AssertBool" -]) -runSolidityTest("TestSortedDoublyLLUpdateKey", [ - "SortedDoublyLL", - "AssertAddress", - "AssertUint", - "AssertBool" -]) diff --git a/test/unit/helpers/runSolidityTest.js b/test/unit/helpers/runSolidityTest.js deleted file mode 100644 index abad6ed7..00000000 --- a/test/unit/helpers/runSolidityTest.js +++ /dev/null @@ -1,102 +0,0 @@ -// Based on https://github.com/aragon/aragonOS/blob/4bbe3e96fc5a3aa6340b11ec67e6550029da7af9/test/helpers/runSolidityTest.js -import abi from "ethereumjs-abi" -import {ethers} from "hardhat" -import {eventSig} from "../../../utils/helpers" -import {assert} from "chai" -const HOOKS_MAP = { - beforeAll: "before", - beforeEach: "beforeEach", - afterEach: "afterEach", - afterAll: "afterAll" -} - -const processResult = async txRes => { - const receipt = await txRes.wait() - const eventSignature = eventSig("TestEvent(bool,string)") - const rawLogs = receipt.logs.filter(log => log.topics[0] === eventSignature) - - // Event defined in the libraries used by contracts/test/helpers/truffle/Assert.sol - - rawLogs.forEach(log => { - const result = abi.rawDecode( - ["bool"], - Buffer.from(log.topics[1].slice(2), "hex") - )[0] - const message = abi.rawDecode( - ["string"], - Buffer.from(log.data.slice(2), "hex") - )[0] - - if (!result) { - assert.fail(message || "No assertions made") - } else { - assert.isOk(result) - } - }) -} - -/** - * Runs a solidity test file, via javascript. - * Required to smooth over some technical problems in solidity-coverage - * - * @param {string} c Name of Solidity test file - * @param {Array} libs Array of names of Solidity libraries to link with test file - * @param {Object} mochaContext Mocha context - */ -function runSolidityTest(c, libs, mochaContext) { - describe(c, () => { - const artifact = hre.artifacts.readArtifactSync(c) - - let deployed - - before(async () => { - const libraries = {} - for (const libName of libs) { - libraries[libName] = ( - await (await ethers.getContractFactory(libName)).deploy() - ).address - } - - const fac = await ethers.getContractFactory(c, { - libraries: libraries - }) - - deployed = await fac.deploy() - }) - - mochaContext("> Solidity test", () => { - artifact.abi.forEach(itf => { - const name = itf.name - - if (itf.type === "function") { - if ( - [ - "beforeAll", - "beforeEach", - "afterEach", - "afterAll" - ].includes(itf.name) - ) { - // Set up hooks - global[HOOKS_MAP[name]](async () => { - const tx = await deployed[name]() - await processResult(tx) - }) - } else if (itf.name.startsWith("test")) { - it(itf.name, async () => { - const tx = await deployed[name]() - await processResult(tx) - }) - } - } - }) - }) - }) -} - -// Bind the functions for ease of use, and provide .only() and .skip() hooks -const fn = (c, libs) => runSolidityTest(c, libs, context) -fn.only = (c, libs) => runSolidityTest(c, libs, context.only) -fn.skip = (c, libs) => runSolidityTest(c, libs, context.skip) - -module.exports = fn From a6859791fe19494fa015566670edeb93a5708575 Mon Sep 17 00:00:00 2001 From: RiccardoBiosas Date: Wed, 13 Jul 2022 06:17:02 -0500 Subject: [PATCH 4/5] tests(truffle-helpers): Removed unused truffle helpers for solidity tests --- contracts/test/helpers/truffle/Assert.sol | 1350 ----------------- .../test/helpers/truffle/AssertAddress.sol | 123 -- .../helpers/truffle/AssertAddressArray.sol | 307 ---- .../truffle/AssertAddressPayableArray.sol | 307 ---- .../test/helpers/truffle/AssertBalance.sol | 119 -- contracts/test/helpers/truffle/AssertBool.sol | 256 ---- .../test/helpers/truffle/AssertBytes32.sol | 125 -- .../helpers/truffle/AssertBytes32Array.sol | 307 ---- .../test/helpers/truffle/AssertGeneral.sol | 49 - contracts/test/helpers/truffle/AssertInt.sol | 420 ----- .../test/helpers/truffle/AssertIntArray.sol | 351 ----- .../test/helpers/truffle/AssertString.sol | 259 ---- contracts/test/helpers/truffle/AssertUint.sol | 407 ----- .../test/helpers/truffle/AssertUintArray.sol | 340 ----- 14 files changed, 4720 deletions(-) delete mode 100644 contracts/test/helpers/truffle/Assert.sol delete mode 100644 contracts/test/helpers/truffle/AssertAddress.sol delete mode 100644 contracts/test/helpers/truffle/AssertAddressArray.sol delete mode 100644 contracts/test/helpers/truffle/AssertAddressPayableArray.sol delete mode 100644 contracts/test/helpers/truffle/AssertBalance.sol delete mode 100644 contracts/test/helpers/truffle/AssertBool.sol delete mode 100644 contracts/test/helpers/truffle/AssertBytes32.sol delete mode 100644 contracts/test/helpers/truffle/AssertBytes32Array.sol delete mode 100644 contracts/test/helpers/truffle/AssertGeneral.sol delete mode 100644 contracts/test/helpers/truffle/AssertInt.sol delete mode 100644 contracts/test/helpers/truffle/AssertIntArray.sol delete mode 100644 contracts/test/helpers/truffle/AssertString.sol delete mode 100644 contracts/test/helpers/truffle/AssertUint.sol delete mode 100644 contracts/test/helpers/truffle/AssertUintArray.sol diff --git a/contracts/test/helpers/truffle/Assert.sol b/contracts/test/helpers/truffle/Assert.sol deleted file mode 100644 index 7b49108a..00000000 --- a/contracts/test/helpers/truffle/Assert.sol +++ /dev/null @@ -1,1350 +0,0 @@ -// This file taken from here: https://raw.githubusercontent.com/smartcontractproduction/sol-unit/master/contracts/src/Assertions.sol -// It was renamed to Assert.sol by Tim Coulter. Refactored for solidity 0.5.0 by Cruz Molina. -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -import "./AssertString.sol"; -import "./AssertBytes32.sol"; -import "./AssertAddress.sol"; -import "./AssertBool.sol"; -import "./AssertUint.sol"; -import "./AssertInt.sol"; -import "./AssertUintArray.sol"; -import "./AssertIntArray.sol"; -import "./AssertAddressArray.sol"; -// import "./AssertAddressPayableArray.sol"; -// ^would require an oldAssert.sol (0.4.0) & a newAssert.sol (0.5.0) -import "./AssertBytes32Array.sol"; -import "./AssertBalance.sol"; -import "./AssertGeneral.sol"; - -/* - File: Assertions.slb - - Author: Andreas Olofsson (androlo1980@gmail.com) - - Library: Assertions - - Assertions for unit testing contracts. Tests are run with the - - unit-testing framework. - - (start code) - contract ModAdder { - - function addMod(uint a, uint b, uint modulus) constant returns (uint sum) { - if (modulus == 0) - throw; - return addmod(a, b, modulus); - } - - } - - contract SomeTest { - using Assertions for uint; - - function testAdd() { - var adder = new ModAdder(); - adder.addMod(50, 66, 30).equal(26, "addition returned the wrong sum"); - } - } - (end) - - It is also possible to extend , to have all bindings (using) properly set up. - - (start code) - - contract SomeTest is Test { - - function testAdd() { - var adder = new ModAdder(); - adder.addMod(50, 66, 30).equal(26, "addition returned the wrong sum"); - } - } - (end) -*/ - -library Assert { - // ************************************** general ************************************** - - /* - Function: fail() - - Mark the test as failed. - - Params: - message (string) - A message associated with the failure. - - Returns: - result (bool) - false. - */ - function fail(string memory message) internal returns (bool result) { - return AssertGeneral.fail(message); - } - - // ************************************** strings ************************************** - - /* - Function: equal(string) - - Assert that two strings are equal. - - : _stringsEqual(A, B) == true - - Params: - A (string) - The first string. - B (string) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - string memory a, - string memory b, - string memory message - ) internal returns (bool result) { - return AssertString.equal(a, b, message); - } - - /* - Function: notEqual(string) - - Assert that two strings are not equal. - - : _stringsEqual(A, B) == false - - Params: - A (string) - The first string. - B (string) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - string memory a, - string memory b, - string memory message - ) internal returns (bool result) { - return AssertString.notEqual(a, b, message); - } - - /* - Function: isEmpty(string) - - Assert that a string is empty. - - : _stringsEqual(str, STRING_NULL) == true - - Params: - str (string) - The string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isEmpty(string memory str, string memory message) internal returns (bool result) { - return AssertString.isEmpty(str, message); - } - - /* - Function: isNotEmpty(string) - - Assert that a string is not empty. - - : _stringsEqual(str, STRING_NULL) == false - - Params: - str (string) - The string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isNotEmpty(string memory str, string memory message) internal returns (bool result) { - return AssertString.isNotEmpty(str, message); - } - - // ************************************** bytes32 ************************************** - - /* - Function: equal(bytes32) - - Assert that two 'bytes32' are equal. - - : A == B - - Params: - A (bytes32) - The first 'bytes32'. - B (bytes32) - The second 'bytes32'. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - bytes32 a, - bytes32 b, - string memory message - ) internal returns (bool result) { - return AssertBytes32.equal(a, b, message); - } - - /* - Function: notEqual(bytes32) - - Assert that two 'bytes32' are not equal. - - : A != B - - Params: - A (bytes32) - The first 'bytes32'. - B (bytes32) - The second 'bytes32'. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - bytes32 a, - bytes32 b, - string memory message - ) internal returns (bool result) { - return AssertBytes32.notEqual(a, b, message); - } - - /* - Function: isZero(bytes32) - - Assert that a 'bytes32' is zero. - - : bts == BYTES32_NULL - - Params: - bts (bytes32) - The 'bytes32'. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isZero(bytes32 bts, string memory message) internal returns (bool result) { - return AssertBytes32.isZero(bts, message); - } - - /* - Function: isNotZero(bytes32) - - Assert that a 'bytes32' is not zero. - - : bts != BYTES32_NULL - - Params: - bts (bytes32) - The 'bytes32'. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isNotZero(bytes32 bts, string memory message) internal returns (bool result) { - return AssertBytes32.isNotZero(bts, message); - } - - // ************************************** address ************************************** - - /* - Function: equal(address) - - Assert that two addresses are equal. - - : A == B - - Params: - A (address) - The first address. - B (address) - The second address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - address a, - address b, - string memory message - ) internal returns (bool result) { - return AssertAddress.equal(a, b, message); - } - - /* - Function: notEqual(address) - - Assert that two addresses are not equal. - - : A != B - - Params: - A (address) - The first address. - B (address) - The second address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - address a, - address b, - string memory message - ) internal returns (bool result) { - return AssertAddress.notEqual(a, b, message); - } - - /* - Function: isZero(address) - - Assert that an address is zero. - - : addr == ADDRESS_NULL - - Params: - addr (address) - The address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isZero(address addr, string memory message) internal returns (bool result) { - return AssertAddress.isZero(addr, message); - } - - /* - Function: isNotZero(address) - - Assert that an address is not zero. - - : addr != ADDRESS_NULL - - Params: - addr (address) - The address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isNotZero(address addr, string memory message) internal returns (bool result) { - return AssertAddress.isNotZero(addr, message); - } - - // ************************************** bool ************************************** - - /* - Function: isTrue - - Assert that a boolean is 'true'. - - : b == true - - Params: - b (bool) - The boolean. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isTrue(bool b, string memory message) internal returns (bool result) { - return AssertBool.isTrue(b, message); - } - - /* - Function: isFalse - - Assert that a boolean is 'false'. - - : b == false - - Params: - b (bool) - The boolean. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isFalse(bool b, string memory message) internal returns (bool result) { - return AssertBool.isFalse(b, message); - } - - /* - Function: equal(bool) - - Assert that two booleans are equal. - - : A == B - - Params: - A (bool) - The first boolean. - B (bool) - The second boolean. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - bool a, - bool b, - string memory message - ) internal returns (bool result) { - return AssertBool.equal(a, b, message); - } - - /* - Function: notEqual(bool) - - Assert that two booleans are not equal. - - : A != B - - Params: - A (bool) - The first boolean. - B (bool) - The second boolean. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - bool a, - bool b, - string memory message - ) internal returns (bool result) { - return AssertBool.notEqual(a, b, message); - } - - // ************************************** uint ************************************** - - /* - Function: equal(uint) - - Assert that two (256 bit) unsigned integers are equal. - - : A == B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - uint256 a, - uint256 b, - string memory message - ) internal returns (bool result) { - return AssertUint.equal(a, b, message); - } - - /* - Function: notEqual(uint) - - Assert that two (256 bit) unsigned integers are not equal. - - : A != B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - uint256 a, - uint256 b, - string memory message - ) internal returns (bool result) { - return AssertUint.notEqual(a, b, message); - } - - /* - Function: isAbove(uint) - - Assert that the uint 'A' is greater than the uint 'B'. - - : A > B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAbove( - uint256 a, - uint256 b, - string memory message - ) internal returns (bool result) { - return AssertUint.isAbove(a, b, message); - } - - /* - Function: isAtLeast(uint) - - Assert that the uint 'A' is greater than or equal to the uint 'B'. - - : A >= B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAtLeast( - uint256 a, - uint256 b, - string memory message - ) internal returns (bool result) { - return AssertUint.isAtLeast(a, b, message); - } - - /* - Function: isBelow(uint) - - Assert that the uint 'A' is lesser than the uint 'B'. - - : A < B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isBelow( - uint256 a, - uint256 b, - string memory message - ) internal returns (bool result) { - return AssertUint.isBelow(a, b, message); - } - - /* - Function: isAtMost(uint) - - Assert that the uint 'A' is lesser than or equal to the uint 'B'. - - : A <= B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAtMost( - uint256 a, - uint256 b, - string memory message - ) internal returns (bool result) { - return AssertUint.isAtMost(a, b, message); - } - - /* - Function: isZero(uint) - - Assert that a (256 bit) unsigned integer is 0. - - : number == 0 - - Params: - number (uint) - The uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isZero(uint256 number, string memory message) internal returns (bool result) { - return AssertUint.isZero(number, message); - } - - /* - Function: isNotZero(uint) - - Assert that a (256 bit) unsigned integer is not 0. - - : number != 0 - - Params: - number (uint) - The uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isNotZero(uint256 number, string memory message) internal returns (bool result) { - return AssertUint.isNotZero(number, message); - } - - // ************************************** int ************************************** - - /* - Function: equal(int) - - Assert that two (256 bit) signed integers are equal. - - : A == B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - int256 a, - int256 b, - string memory message - ) internal returns (bool result) { - return AssertInt.equal(a, b, message); - } - - /* - Function: notEqual(int) - - Assert that two (256 bit) signed integers are not equal. - - : A != B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - int256 a, - int256 b, - string memory message - ) internal returns (bool result) { - return AssertInt.notEqual(a, b, message); - } - - /* - Function: isAbove(int) - - Assert that the int 'A' is greater than the int 'B'. - - : A > B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAbove( - int256 a, - int256 b, - string memory message - ) internal returns (bool result) { - return AssertInt.isAbove(a, b, message); - } - - /* - Function: isAtLeast(int) - - Assert that the int 'A' is greater than or equal to the int 'B'. - - : A >= B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAtLeast( - int256 a, - int256 b, - string memory message - ) internal returns (bool result) { - return AssertInt.isAtLeast(a, b, message); - } - - /* - Function: isBelow(int) - - Assert that the int 'A' is lesser than the int 'B'. - - : A < B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isBelow( - int256 a, - int256 b, - string memory message - ) internal returns (bool result) { - return AssertInt.isBelow(a, b, message); - } - - /* - Function: isAtMost(int) - - Assert that the int 'A' is lesser than or equal to the int 'B'. - - : A <= B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAtMost( - int256 a, - int256 b, - string memory message - ) internal returns (bool result) { - return AssertInt.isAtMost(a, b, message); - } - - /* - Function: isZero(int) - - Assert that a (256 bit) signed integer is 0. - - : number == 0 - - Params: - number (int) - The int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isZero(int256 number, string memory message) internal returns (bool result) { - return AssertInt.isZero(number, message); - } - - /* - Function: isNotZero(int) - - Assert that a (256 bit) signed integer is not 0. - - : number != 0 - - Params: - number (int) - The int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isNotZero(int256 number, string memory message) internal returns (bool result) { - return AssertInt.isNotZero(number, message); - } - - // ************************************** uint[] ************************************** - - /* - Function: equal(uint[]) - - Assert that two 'uint[ ]' are equal. - - : arrA.length == arrB.length - - and, for all valid indices 'i' - - : arrA[i] == arrB[i] - - Params: - A (uint[]) - The first array. - B (uint[]) - The second array. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - uint256[] memory arrA, - uint256[] memory arrB, - string memory message - ) internal returns (bool result) { - return AssertUintArray.equal(arrA, arrB, message); - } - - /* - Function: notEqual(uint[]) - - Assert that two 'uint[]' are not equal. - - : arrA.length != arrB.length - - or, for some valid index 'i' - - : arrA[i] != arrB[i] - - Params: - A (uint[]) - The first string. - B (uint[]) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - uint256[] memory arrA, - uint256[] memory arrB, - string memory message - ) internal returns (bool result) { - return AssertUintArray.notEqual(arrA, arrB, message); - } - - /* - Function: lengthEqual(uint[]) - - Assert that the length of a 'uint[]' is equal to a given value. - - : arr.length == length - - Params: - arr (uint[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthEqual( - uint256[] memory arr, - uint256 length, - string memory message - ) internal returns (bool result) { - return AssertUintArray.lengthEqual(arr, length, message); - } - - /* - Function: lengthNotEqual(uint[]) - - Assert that the length of a 'uint[]' is not equal to a given value. - - : arr.length != length - - Params: - arr (uint[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthNotEqual( - uint256[] memory arr, - uint256 length, - string memory message - ) internal returns (bool result) { - return AssertUintArray.lengthNotEqual(arr, length, message); - } - - // ************************************** int[] ************************************** - - /* - Function: equal(int[]) - - Assert that two 'int[]' are equal. - - : arrA.length == arrB.length - - and, for all valid indices 'i' - - : arrA[i] == arrB[i] - - Params: - A (int[]) - The first array. - B (int[]) - The second array. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - int256[] memory arrA, - int256[] memory arrB, - string memory message - ) internal returns (bool result) { - return AssertIntArray.equal(arrA, arrB, message); - } - - /* - Function: notEqual(int[]) - - Assert that two 'int[]' are not equal. - - : arrA.length != arrB.length - - or, for some valid index 'i' - - : arrA[i] != arrB[i] - - Params: - A (int[]) - The first string. - B (int[]) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - int256[] memory arrA, - int256[] memory arrB, - string memory message - ) internal returns (bool result) { - return AssertIntArray.notEqual(arrA, arrB, message); - } - - /* - Function: lengthEqual(int[]) - - Assert that the length of an 'int[]' is equal to a given value. - - : arr.length == length - - Params: - arr (int[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthEqual( - int256[] memory arr, - uint256 length, - string memory message - ) internal returns (bool result) { - return AssertIntArray.lengthEqual(arr, length, message); - } - - /* - Function: lengthNotEqual(int[]) - - Assert that the length of an 'int[]' is not equal to a given value. - - : arr.length != length - - Params: - arr (int[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthNotEqual( - int256[] memory arr, - uint256 length, - string memory message - ) internal returns (bool result) { - return AssertIntArray.lengthNotEqual(arr, length, message); - } - - // ************************************** address[] ************************************** - - /* - Function: equal(address[]) - - Assert that two 'address[]' are equal. - - : arrA.length == arrB.length - - and, for all valid indices 'i' - - : arrA[i] == arrB[i] - - Params: - A (address[]) - The first array. - B (address[]) - The second array. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - address[] memory arrA, - address[] memory arrB, - string memory message - ) internal returns (bool result) { - return AssertAddressArray.equal(arrA, arrB, message); - } - - /* - Function: notEqual(address[]) - - Assert that two 'address[]' are not equal. - - : arrA.length != arrB.length - - or, for some valid index 'i' - - : arrA[i] != arrB[i] - - Params: - A (address[]) - The first string. - B (address[]) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - address[] memory arrA, - address[] memory arrB, - string memory message - ) internal returns (bool result) { - return AssertAddressArray.notEqual(arrA, arrB, message); - } - - /* - Function: lengthEqual(address[]) - - Assert that the length of an 'address[]' is equal to a given value. - - : arr.length == length - - Params: - arr (address[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthEqual( - address[] memory arr, - uint256 length, - string memory message - ) internal returns (bool result) { - return AssertAddressArray.lengthEqual(arr, length, message); - } - - /* - Function: lengthNotEqual(address[]) - - Assert that the length of an 'address[]' is not equal to a given value. - - : arr.length != length - - Params: - arr (address[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthNotEqual( - address[] memory arr, - uint256 length, - string memory message - ) internal returns (bool result) { - return AssertAddressArray.lengthNotEqual(arr, length, message); - } - - // ************************************** address payable[] ************************************** - - /* - Function: equal(address payable[]) - - Assert that two 'address payable[]' are equal. - - : arrA.length == arrB.length - - and, for all valid indices 'i' - - : arrA[i] == arrB[i] - - Params: - A (address payable[]) - The first array. - B (address payable[]) - The second array. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - // function equal(address payable[] memory arrA, address payable[] memory arrB, string memory message) internal returns (bool result) { - // return AssertAddressPayableArray.equal(arrA, arrB, message); - // } - - /* - Function: notEqual(address payable[]) - - Assert that two 'address payable[]' are not equal. - - : arrA.length != arrB.length - - or, for some valid index 'i' - - : arrA[i] != arrB[i] - - Params: - A (address payable[]) - The first string. - B (address payable[]) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - // function notEqual(address payable[] memory arrA, address payable[] memory arrB, string memory message) internal returns (bool result) { - // return AssertAddressPayableArray.notEqual(arrA, arrB, message); - // } - - /* - Function: lengthEqual(address payable[]) - - Assert that the length of an 'address payable[]' is equal to a given value. - - : arr.length == length - - Params: - arr (address payable[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - // function lengthEqual(address payable[] memory arr, uint length, string memory message) internal returns (bool result) { - // return AssertAddressPayableArray.lengthEqual(arr, length, message); - // } - - /* - Function: lengthNotEqual(address payable[]) - - Assert that the length of an 'address payable[]' is not equal to a given value. - - : arr.length != length - - Params: - arr (address payable[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - // function lengthNotEqual(address payable[] memory arr, uint length, string memory message) internal returns (bool result) { - // return AssertAddressPayableArray.lengthNotEqual(arr, length, message); - // } - - // ************************************** bytes32[] ************************************** - - /* - Function: equal(bytes32[]) - - Assert that two 'bytes32[]' are equal. - - : arrA.length == arrB.length - - and, for all valid indices 'i' - - : arrA[i] == arrB[i] - - Params: - A (bytes32[]) - The first array. - B (bytes32[]) - The second array. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - bytes32[] memory arrA, - bytes32[] memory arrB, - string memory message - ) internal returns (bool result) { - return AssertBytes32Array.equal(arrA, arrB, message); - } - - /* - Function: notEqual(bytes32[]) - - Assert that two 'bytes32[]' are not equal. - - : arrA.length != arrB.length - - or, for some valid index 'i' - - : arrA[i] != arrB[i] - - Params: - A (bytes32[]) - The first string. - B (bytes32[]) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - bytes32[] memory arrA, - bytes32[] memory arrB, - string memory message - ) internal returns (bool result) { - return AssertBytes32Array.notEqual(arrA, arrB, message); - } - - /* - Function: lengthEqual(bytes32[]) - - Assert that the length of an 'bytes32[]' is equal to a given value. - - : arr.length == length - - Params: - arr (bytes32[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthEqual( - bytes32[] memory arr, - uint256 length, - string memory message - ) internal returns (bool result) { - return AssertBytes32Array.lengthEqual(arr, length, message); - } - - /* - Function: lengthNotEqual(bytes32[]) - - Assert that the length of an 'bytes32[]' is not equal to a given value. - - : arr.length != length - - Params: - arr (bytes32[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthNotEqual( - bytes32[] memory arr, - uint256 length, - string memory message - ) internal returns (bool result) { - return AssertBytes32Array.lengthNotEqual(arr, length, message); - } - - // ************************************** balances ************************************** - - /* - Function: balanceEqual - - Assert that the balance of an account 'A' is equal to a given number 'b'. - - : A.balance = b - - Params: - A (address) - The first address. - b (uint) - The balance. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function balanceEqual( - address a, - uint256 b, - string memory message - ) internal returns (bool result) { - return AssertBalance.balanceEqual(a, b, message); - } - - /* - Function: balanceNotEqual - - Assert that the balance of an account 'A' is not equal to a given number 'b'. - - : A.balance != b - - Params: - A (address) - The first address. - b (uint) - The balance. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function balanceNotEqual( - address a, - uint256 b, - string memory message - ) internal returns (bool result) { - return AssertBalance.balanceNotEqual(a, b, message); - } - - /* - Function: balanceIsZero - - Assert that the balance of an account 'A' is zero. - - : A.balance == 0 - - Params: - A (address) - The first address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function balanceIsZero(address a, string memory message) internal returns (bool result) { - return AssertBalance.balanceIsZero(a, message); - } - - /* - Function: balanceIsNotZero - - Assert that the balance of an account 'A' is not zero. - - : A.balance != 0 - - Params: - A (address) - The first address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function balanceIsNotZero(address a, string memory message) internal returns (bool result) { - return AssertBalance.balanceIsNotZero(a, message); - } -} diff --git a/contracts/test/helpers/truffle/AssertAddress.sol b/contracts/test/helpers/truffle/AssertAddress.sol deleted file mode 100644 index b34da42e..00000000 --- a/contracts/test/helpers/truffle/AssertAddress.sol +++ /dev/null @@ -1,123 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertAddress { - // Constant: ADDRESS_NULL - // The null address: 0 - address constant ADDRESS_NULL = 0x0000000000000000000000000000000000000000; - - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** address ************************************** - - /* - Function: equal(address) - - Assert that two addresses are equal. - - : A == B - - Params: - A (address) - The first address. - B (address) - The second address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - address a, - address b, - string memory message - ) public returns (bool result) { - result = (a == b); - _report(result, message); - } - - /* - Function: notEqual(address) - - Assert that two addresses are not equal. - - : A != B - - Params: - A (address) - The first address. - B (address) - The second address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - address a, - address b, - string memory message - ) public returns (bool result) { - result = (a != b); - _report(result, message); - } - - /* - Function: isZero(address) - - Assert that an address is zero. - - : addr == ADDRESS_NULL - - Params: - addr (address) - The address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isZero(address addr, string memory message) public returns (bool result) { - result = (addr == ADDRESS_NULL); - _report(result, message); - } - - /* - Function: isNotZero(address) - - Assert that an address is not zero. - - : addr != ADDRESS_NULL - - Params: - addr (address) - The address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isNotZero(address addr, string memory message) public returns (bool result) { - result = (addr != ADDRESS_NULL); - _report(result, message); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } -} diff --git a/contracts/test/helpers/truffle/AssertAddressArray.sol b/contracts/test/helpers/truffle/AssertAddressArray.sol deleted file mode 100644 index 8f0604d5..00000000 --- a/contracts/test/helpers/truffle/AssertAddressArray.sol +++ /dev/null @@ -1,307 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertAddressArray { - uint8 constant ZERO = uint8(bytes1("0")); - uint8 constant A = uint8(bytes1("a")); - - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** address[] ************************************** - - /* - Function: equal(address[]) - - Assert that two 'address[]' are equal. - - : arrA.length == arrB.length - - and, for all valid indices 'i' - - : arrA[i] == arrB[i] - - Params: - A (address[]) - The first array. - B (address[]) - The second array. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - address[] memory arrA, - address[] memory arrB, - string memory message - ) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint256 i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - _report(result, message); - } - - /* - Function: notEqual(address[]) - - Assert that two 'address[]' are not equal. - - : arrA.length != arrB.length - - or, for some valid index 'i' - - : arrA[i] != arrB[i] - - Params: - A (address[]) - The first string. - B (address[]) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - address[] memory arrA, - address[] memory arrB, - string memory message - ) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint256 i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - result = !result; - _report(result, message); - } - - /* - Function: lengthEqual(address[]) - - Assert that the length of an 'address[]' is equal to a given value. - - : arr.length == length - - Params: - arr (address[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthEqual( - address[] memory arr, - uint256 length, - string memory message - ) public returns (bool result) { - uint256 arrLength = arr.length; - if (arrLength == length) _report(result, ""); - else _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /* - Function: lengthNotEqual(address[]) - - Assert that the length of an 'address[]' is not equal to a given value. - - : arr.length != length - - Params: - arr (address[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthNotEqual( - address[] memory arr, - uint256 length, - string memory message - ) public returns (bool result) { - uint256 arrLength = arr.length; - if (arrLength != arr.length) _report(result, ""); - else _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } - - /* - Function: _utoa(uint) - - Convert an unsigned integer to a string. - - Params: - n (uint) - The unsigned integer. - radix (uint8) - A number between 2 and 16 (inclusive). Characters used are 0-9,a-f - - Returns: - result (string) - The resulting string. - */ - function _utoa(uint256 n, uint8 radix) internal pure returns (string memory) { - if (n == 0 || radix < 2 || radix > 16) return "0"; - bytes memory bts = new bytes(256); - uint256 i; - while (n > 0) { - bts[i++] = _utoa(uint8(n % radix)); // Turn it to ascii. - n /= radix; - } - // Reverse - bytes memory rev = new bytes(i); - for (uint256 j = 0; j < i; j++) rev[j] = bts[i - j - 1]; - return string(rev); - } - - /* - Function: _utoa(uint8) - - Convert an unsigned 8-bit integer to its ASCII byte representation. Numbers 0-9 are converted to '0'-'9', - numbers 10-16 to 'a'-'f'. Numbers larger then 16 return the null byte. - - Params: - u (uint8) - The unsigned 8-bit integer. - - Returns: - result (string) - The ASCII byte. - */ - function _utoa(uint8 u) internal pure returns (bytes1) { - if (u < 10) return bytes1(u + ZERO); - else if (u < 16) return bytes1(u - 10 + A); - else return 0; - } - - /* - function htoa(address addr) constant returns (string) { - bytes memory bts = new bytes(40); - bytes20 addrBts = bytes20(addr); - for (uint i = 0; i < 20; i++) { - bts[2*i] = addrBts[i] % 16; - bts[2*i + 1] = (addrBts[i] / 16) % 16; - } - return string(bts); - } - */ - - /* - Function: _tag(string) - - Add a tag to a string. The 'value' and 'tag' strings are returned on the form "tag: value". - - Params: - value (string) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: value" - */ - function _tag(string memory value, string memory tag) internal pure returns (string memory) { - bytes memory valueB = bytes(value); - bytes memory tagB = bytes(tag); - - uint256 vl = valueB.length; - uint256 tl = tagB.length; - - bytes memory newB = new bytes(vl + tl + 2); - - uint256 i; - uint256 j; - - for (i = 0; i < tl; i++) newB[j++] = tagB[i]; - newB[j++] = ":"; - newB[j++] = " "; - for (i = 0; i < vl; i++) newB[j++] = valueB[i]; - - return string(newB); - } - - /* - Function: _tag(uint) - - Add a tag to an uint. - - Params: - value (uint) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: _utoa(value)" - */ - function _tag(uint256 value, string memory tag) internal pure returns (string memory) { - string memory nstr = _utoa(value, 10); - return _tag(nstr, tag); - } - - /* - Function: _appendTagged(string, string) - - Append two tagged values to a string. - - Params: - tagged0 (string) - The first tagged value. - tagged1 (string) - The second tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged0, tagged1)" - */ - function _appendTagged( - string memory tagged0, - string memory tagged1, - string memory str - ) internal pure returns (string memory) { - bytes memory tagged0B = bytes(tagged0); - bytes memory tagged1B = bytes(tagged1); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 t0l = tagged0B.length; - uint256 t1l = tagged1B.length; - - bytes memory newB = new bytes(sl + t0l + t1l + 5); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < t0l; i++) newB[j++] = tagged0B[i]; - newB[j++] = ","; - newB[j++] = " "; - for (i = 0; i < t1l; i++) newB[j++] = tagged1B[i]; - newB[j++] = ")"; - - return string(newB); - } -} diff --git a/contracts/test/helpers/truffle/AssertAddressPayableArray.sol b/contracts/test/helpers/truffle/AssertAddressPayableArray.sol deleted file mode 100644 index decf1b25..00000000 --- a/contracts/test/helpers/truffle/AssertAddressPayableArray.sol +++ /dev/null @@ -1,307 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity ^0.8.8; - -library AssertAddressPayableArray { - uint8 constant ZERO = uint8(bytes1("0")); - uint8 constant A = uint8(bytes1("a")); - - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** address payable[] ************************************** - - /* - Function: equal(address payable[]) - - Assert that two 'address payable[]' are equal. - - : arrA.length == arrB.length - - and, for all valid indices 'i' - - : arrA[i] == arrB[i] - - Params: - A (address payable[]) - The first array. - B (address payable[]) - The second array. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - address payable[] memory arrA, - address payable[] memory arrB, - string memory message - ) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint256 i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - _report(result, message); - } - - /* - Function: notEqual(address payable[]) - - Assert that two 'address payable[]' are not equal. - - : arrA.length != arrB.length - - or, for some valid index 'i' - - : arrA[i] != arrB[i] - - Params: - A (address payable[]) - The first string. - B (address payable[]) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - address payable[] memory arrA, - address payable[] memory arrB, - string memory message - ) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint256 i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - result = !result; - _report(result, message); - } - - /* - Function: lengthEqual(address payable[]) - - Assert that the length of an 'address payable[]' is equal to a given value. - - : arr.length == length - - Params: - arr (address payable[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthEqual( - address payable[] memory arr, - uint256 length, - string memory message - ) public returns (bool result) { - uint256 arrLength = arr.length; - if (arrLength == length) _report(result, ""); - else _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /* - Function: lengthNotEqual(address payable[]) - - Assert that the length of an 'address payable[]' is not equal to a given value. - - : arr.length != length - - Params: - arr (address payable[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthNotEqual( - address payable[] memory arr, - uint256 length, - string memory message - ) public returns (bool result) { - uint256 arrLength = arr.length; - if (arrLength != arr.length) _report(result, ""); - else _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } - - /* - Function: _utoa(uint) - - Convert an unsigned integer to a string. - - Params: - n (uint) - The unsigned integer. - radix (uint8) - A number between 2 and 16 (inclusive). Characters used are 0-9,a-f - - Returns: - result (string) - The resulting string. - */ - function _utoa(uint256 n, uint8 radix) internal pure returns (string memory) { - if (n == 0 || radix < 2 || radix > 16) return "0"; - bytes memory bts = new bytes(256); - uint256 i; - while (n > 0) { - bts[i++] = _utoa(uint8(n % radix)); // Turn it to ascii. - n /= radix; - } - // Reverse - bytes memory rev = new bytes(i); - for (uint256 j = 0; j < i; j++) rev[j] = bts[i - j - 1]; - return string(rev); - } - - /* - Function: _utoa(uint8) - - Convert an unsigned 8-bit integer to its ASCII byte representation. Numbers 0-9 are converted to '0'-'9', - numbers 10-16 to 'a'-'f'. Numbers larger then 16 return the null byte. - - Params: - u (uint8) - The unsigned 8-bit integer. - - Returns: - result (string) - The ASCII byte. - */ - function _utoa(uint8 u) internal pure returns (bytes1) { - if (u < 10) return bytes1(u + ZERO); - else if (u < 16) return bytes1(u - 10 + A); - else return 0; - } - - /* - function htoa(address addr) constant returns (string) { - bytes memory bts = new bytes(40); - bytes20 addrBts = bytes20(addr); - for (uint i = 0; i < 20; i++) { - bts[2*i] = addrBts[i] % 16; - bts[2*i + 1] = (addrBts[i] / 16) % 16; - } - return string(bts); - } - */ - - /* - Function: _tag(string) - - Add a tag to a string. The 'value' and 'tag' strings are returned on the form "tag: value". - - Params: - value (string) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: value" - */ - function _tag(string memory value, string memory tag) internal pure returns (string memory) { - bytes memory valueB = bytes(value); - bytes memory tagB = bytes(tag); - - uint256 vl = valueB.length; - uint256 tl = tagB.length; - - bytes memory newB = new bytes(vl + tl + 2); - - uint256 i; - uint256 j; - - for (i = 0; i < tl; i++) newB[j++] = tagB[i]; - newB[j++] = ":"; - newB[j++] = " "; - for (i = 0; i < vl; i++) newB[j++] = valueB[i]; - - return string(newB); - } - - /* - Function: _tag(uint) - - Add a tag to an uint. - - Params: - value (uint) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: _utoa(value)" - */ - function _tag(uint256 value, string memory tag) internal pure returns (string memory) { - string memory nstr = _utoa(value, 10); - return _tag(nstr, tag); - } - - /* - Function: _appendTagged(string, string) - - Append two tagged values to a string. - - Params: - tagged0 (string) - The first tagged value. - tagged1 (string) - The second tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged0, tagged1)" - */ - function _appendTagged( - string memory tagged0, - string memory tagged1, - string memory str - ) internal pure returns (string memory) { - bytes memory tagged0B = bytes(tagged0); - bytes memory tagged1B = bytes(tagged1); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 t0l = tagged0B.length; - uint256 t1l = tagged1B.length; - - bytes memory newB = new bytes(sl + t0l + t1l + 5); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < t0l; i++) newB[j++] = tagged0B[i]; - newB[j++] = ","; - newB[j++] = " "; - for (i = 0; i < t1l; i++) newB[j++] = tagged1B[i]; - newB[j++] = ")"; - - return string(newB); - } -} diff --git a/contracts/test/helpers/truffle/AssertBalance.sol b/contracts/test/helpers/truffle/AssertBalance.sol deleted file mode 100644 index cd3b4aba..00000000 --- a/contracts/test/helpers/truffle/AssertBalance.sol +++ /dev/null @@ -1,119 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertBalance { - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** balances ************************************** - - /* - Function: balanceEqual - - Assert that the balance of an account 'A' is equal to a given number 'b'. - - : A.balance = b - - Params: - A (address) - The first address. - b (uint) - The balance. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function balanceEqual( - address a, - uint256 b, - string memory message - ) public returns (bool result) { - result = (a.balance == b); - _report(result, message); - } - - /* - Function: balanceNotEqual - - Assert that the balance of an account 'A' is not equal to a given number 'b'. - - : A.balance != b - - Params: - A (address) - The first address. - b (uint) - The balance. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function balanceNotEqual( - address a, - uint256 b, - string memory message - ) public returns (bool result) { - result = (a.balance != b); - _report(result, message); - } - - /* - Function: balanceIsZero - - Assert that the balance of an account 'A' is zero. - - : A.balance == 0 - - Params: - A (address) - The first address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function balanceIsZero(address a, string memory message) public returns (bool result) { - result = (a.balance == 0); - _report(result, message); - } - - /* - Function: balanceIsNotZero - - Assert that the balance of an account 'A' is not zero. - - : A.balance != 0 - - Params: - A (address) - The first address. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function balanceIsNotZero(address a, string memory message) public returns (bool result) { - result = (a.balance != 0); - _report(result, message); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } -} diff --git a/contracts/test/helpers/truffle/AssertBool.sol b/contracts/test/helpers/truffle/AssertBool.sol deleted file mode 100644 index 0fff3159..00000000 --- a/contracts/test/helpers/truffle/AssertBool.sol +++ /dev/null @@ -1,256 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertBool { - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** bool ************************************** - - /* - Function: isTrue - - Assert that a boolean is 'true'. - - : b == true - - Params: - b (bool) - The boolean. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isTrue(bool b, string memory message) public returns (bool result) { - result = b; - _report(result, message); - } - - /* - Function: isFalse - - Assert that a boolean is 'false'. - - : b == false - - Params: - b (bool) - The boolean. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isFalse(bool b, string memory message) public returns (bool result) { - result = !b; - _report(result, message); - } - - /* - Function: equal(bool) - - Assert that two booleans are equal. - - : A == B - - Params: - A (bool) - The first boolean. - B (bool) - The second boolean. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - bool a, - bool b, - string memory message - ) public returns (bool result) { - result = (a == b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: notEqual(bool) - - Assert that two booleans are not equal. - - : A != B - - Params: - A (bool) - The first boolean. - B (bool) - The second boolean. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - bool a, - bool b, - string memory message - ) public returns (bool result) { - result = (a != b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } - - /* - Function: _ltoa - - Convert an boolean to a string. - - Params: - val (bool) - The boolean. - - Returns: - result (string) - "true" if true, "false" if false. - */ - function _ltoa(bool val) internal pure returns (string memory) { - bytes memory b; - if (val) { - b = new bytes(4); - b[0] = "t"; - b[1] = "r"; - b[2] = "u"; - b[3] = "e"; - return string(b); - } else { - b = new bytes(5); - b[0] = "f"; - b[1] = "a"; - b[2] = "l"; - b[3] = "s"; - b[4] = "e"; - return string(b); - } - } - - /* - function htoa(address addr) constant returns (string) { - bytes memory bts = new bytes(40); - bytes20 addrBts = bytes20(addr); - for (uint i = 0; i < 20; i++) { - bts[2*i] = addrBts[i] % 16; - bts[2*i + 1] = (addrBts[i] / 16) % 16; - } - return string(bts); - } - */ - - /* - Function: _tag(string) - - Add a tag to a string. The 'value' and 'tag' strings are returned on the form "tag: value". - - Params: - value (string) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: value" - */ - function _tag(string memory value, string memory tag) internal pure returns (string memory) { - bytes memory valueB = bytes(value); - bytes memory tagB = bytes(tag); - - uint256 vl = valueB.length; - uint256 tl = tagB.length; - - bytes memory newB = new bytes(vl + tl + 2); - - uint256 i; - uint256 j; - - for (i = 0; i < tl; i++) newB[j++] = tagB[i]; - newB[j++] = ":"; - newB[j++] = " "; - for (i = 0; i < vl; i++) newB[j++] = valueB[i]; - - return string(newB); - } - - /* - Function: _tag(bool) - - Add a tag to a boolean. - - Params: - value (bool) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: _ltoa(value)" - */ - function _tag(bool value, string memory tag) internal pure returns (string memory) { - string memory nstr = _ltoa(value); - return _tag(nstr, tag); - } - - /* - Function: _appendTagged(string, string) - - Append two tagged values to a string. - - Params: - tagged0 (string) - The first tagged value. - tagged1 (string) - The second tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged0, tagged1)" - */ - function _appendTagged( - string memory tagged0, - string memory tagged1, - string memory str - ) internal pure returns (string memory) { - bytes memory tagged0B = bytes(tagged0); - bytes memory tagged1B = bytes(tagged1); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 t0l = tagged0B.length; - uint256 t1l = tagged1B.length; - - bytes memory newB = new bytes(sl + t0l + t1l + 5); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < t0l; i++) newB[j++] = tagged0B[i]; - newB[j++] = ","; - newB[j++] = " "; - for (i = 0; i < t1l; i++) newB[j++] = tagged1B[i]; - newB[j++] = ")"; - - return string(newB); - } -} diff --git a/contracts/test/helpers/truffle/AssertBytes32.sol b/contracts/test/helpers/truffle/AssertBytes32.sol deleted file mode 100644 index bf56e7e4..00000000 --- a/contracts/test/helpers/truffle/AssertBytes32.sol +++ /dev/null @@ -1,125 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertBytes32 { - // Constant: BYTES32_NULL - // The null bytes32: 0 - bytes32 constant BYTES32_NULL = 0x0; - - bytes1 constant MINUS = bytes1("-"); - - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** bytes32 ************************************** - - /* - Function: equal(bytes32) - - Assert that two 'bytes32' are equal. - - : A == B - - Params: - A (bytes32) - The first 'bytes32'. - B (bytes32) - The second 'bytes32'. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - bytes32 a, - bytes32 b, - string memory message - ) public returns (bool result) { - result = (a == b); - _report(result, message); - } - - /* - Function: notEqual(bytes32) - - Assert that two 'bytes32' are not equal. - - : A != B - - Params: - A (bytes32) - The first 'bytes32'. - B (bytes32) - The second 'bytes32'. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - bytes32 a, - bytes32 b, - string memory message - ) public returns (bool result) { - result = (a != b); - _report(result, message); - } - - /* - Function: isZero(bytes32) - - Assert that a 'bytes32' is zero. - - : bts == BYTES32_NULL - - Params: - bts (bytes32) - The 'bytes32'. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isZero(bytes32 bts, string memory message) public returns (bool result) { - result = (bts == BYTES32_NULL); - _report(result, message); - } - - /* - Function: isNotZero(bytes32) - - Assert that a 'bytes32' is not zero. - - : bts != BYTES32_NULL - - Params: - bts (bytes32) - The 'bytes32'. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isNotZero(bytes32 bts, string memory message) public returns (bool result) { - result = (bts != BYTES32_NULL); - _report(result, message); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } -} diff --git a/contracts/test/helpers/truffle/AssertBytes32Array.sol b/contracts/test/helpers/truffle/AssertBytes32Array.sol deleted file mode 100644 index 8d57f1a5..00000000 --- a/contracts/test/helpers/truffle/AssertBytes32Array.sol +++ /dev/null @@ -1,307 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertBytes32Array { - uint8 constant ZERO = uint8(bytes1("0")); - uint8 constant A = uint8(bytes1("a")); - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** bytes32[] ************************************** - - /* - Function: equal(bytes32[]) - - Assert that two 'bytes32[]' are equal. - - : arrA.length == arrB.length - - and, for all valid indices 'i' - - : arrA[i] == arrB[i] - - Params: - A (bytes32[]) - The first array. - B (bytes32[]) - The second array. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - bytes32[] memory arrA, - bytes32[] memory arrB, - string memory message - ) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint256 i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - _report(result, message); - } - - /* - Function: notEqual(bytes32[]) - - Assert that two 'bytes32[]' are not equal. - - : arrA.length != arrB.length - - or, for some valid index 'i' - - : arrA[i] != arrB[i] - - Params: - A (bytes32[]) - The first string. - B (bytes32[]) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - bytes32[] memory arrA, - bytes32[] memory arrB, - string memory message - ) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint256 i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - result = !result; - _report(result, message); - } - - /* - Function: lengthEqual(bytes32[]) - - Assert that the length of an 'bytes32[]' is equal to a given value. - - : arr.length == length - - Params: - arr (bytes32[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthEqual( - bytes32[] memory arr, - uint256 length, - string memory message - ) public returns (bool result) { - uint256 arrLength = arr.length; - if (arrLength == length) _report(result, ""); - else _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /* - Function: lengthNotEqual(bytes32[]) - - Assert that the length of an 'bytes32[]' is not equal to a given value. - - : arr.length != length - - Params: - arr (bytes32[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthNotEqual( - bytes32[] memory arr, - uint256 length, - string memory message - ) public returns (bool result) { - uint256 arrLength = arr.length; - if (arrLength != arr.length) _report(result, ""); - else _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } - - /* - Function: _utoa(uint) - - Convert an unsigned integer to a string. - - Params: - n (uint) - The unsigned integer. - radix (uint8) - A number between 2 and 16 (inclusive). Characters used are 0-9,a-f - - Returns: - result (string) - The resulting string. - */ - function _utoa(uint256 n, uint8 radix) internal pure returns (string memory) { - if (n == 0 || radix < 2 || radix > 16) return "0"; - bytes memory bts = new bytes(256); - uint256 i; - while (n > 0) { - bts[i++] = _utoa(uint8(n % radix)); // Turn it to ascii. - n /= radix; - } - // Reverse - bytes memory rev = new bytes(i); - for (uint256 j = 0; j < i; j++) rev[j] = bts[i - j - 1]; - return string(rev); - } - - /* - Function: _utoa(uint8) - - Convert an unsigned 8-bit integer to its ASCII byte representation. Numbers 0-9 are converted to '0'-'9', - numbers 10-16 to 'a'-'f'. Numbers larger then 16 return the null byte. - - Params: - u (uint8) - The unsigned 8-bit integer. - - Returns: - result (string) - The ASCII byte. - */ - function _utoa(uint8 u) internal pure returns (bytes1) { - if (u < 10) return bytes1(u + ZERO); - else if (u < 16) return bytes1(u - 10 + A); - else return 0; - } - - /* - function htoa(address addr) constant returns (string) { - bytes memory bts = new bytes(40); - bytes20 addrBts = bytes20(addr); - for (uint i = 0; i < 20; i++) { - bts[2*i] = addrBts[i] % 16; - bts[2*i + 1] = (addrBts[i] / 16) % 16; - } - return string(bts); - } - - */ - - /* - Function: _tag(string) - - Add a tag to a string. The 'value' and 'tag' strings are returned on the form "tag: value". - - Params: - value (string) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: value" - */ - function _tag(string memory value, string memory tag) internal pure returns (string memory) { - bytes memory valueB = bytes(value); - bytes memory tagB = bytes(tag); - - uint256 vl = valueB.length; - uint256 tl = tagB.length; - - bytes memory newB = new bytes(vl + tl + 2); - - uint256 i; - uint256 j; - - for (i = 0; i < tl; i++) newB[j++] = tagB[i]; - newB[j++] = ":"; - newB[j++] = " "; - for (i = 0; i < vl; i++) newB[j++] = valueB[i]; - - return string(newB); - } - - /* - Function: _tag(uint) - - Add a tag to an uint. - - Params: - value (uint) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: _utoa(value)" - */ - function _tag(uint256 value, string memory tag) internal pure returns (string memory) { - string memory nstr = _utoa(value, 10); - return _tag(nstr, tag); - } - - /* - Function: _appendTagged(string, string) - - Append two tagged values to a string. - - Params: - tagged0 (string) - The first tagged value. - tagged1 (string) - The second tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged0, tagged1)" - */ - function _appendTagged( - string memory tagged0, - string memory tagged1, - string memory str - ) internal pure returns (string memory) { - bytes memory tagged0B = bytes(tagged0); - bytes memory tagged1B = bytes(tagged1); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 t0l = tagged0B.length; - uint256 t1l = tagged1B.length; - - bytes memory newB = new bytes(sl + t0l + t1l + 5); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < t0l; i++) newB[j++] = tagged0B[i]; - newB[j++] = ","; - newB[j++] = " "; - for (i = 0; i < t1l; i++) newB[j++] = tagged1B[i]; - newB[j++] = ")"; - - return string(newB); - } -} diff --git a/contracts/test/helpers/truffle/AssertGeneral.sol b/contracts/test/helpers/truffle/AssertGeneral.sol deleted file mode 100644 index 04d2fb9a..00000000 --- a/contracts/test/helpers/truffle/AssertGeneral.sol +++ /dev/null @@ -1,49 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertGeneral { - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** general ************************************** - - /* - Function: fail() - - Mark the test as failed. - - Params: - message (string) - A message associated with the failure. - - Returns: - result (bool) - false. - */ - function fail(string memory message) public returns (bool result) { - _report(false, message); - return false; - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } -} diff --git a/contracts/test/helpers/truffle/AssertInt.sol b/contracts/test/helpers/truffle/AssertInt.sol deleted file mode 100644 index 764ccfe6..00000000 --- a/contracts/test/helpers/truffle/AssertInt.sol +++ /dev/null @@ -1,420 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertInt { - uint8 constant ZERO = uint8(bytes1("0")); - uint8 constant A = uint8(bytes1("a")); - - bytes1 constant MINUS = bytes1("-"); - - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** int ************************************** - - /* - Function: equal(int) - - Assert that two (256 bit) signed integers are equal. - - : A == B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - int256 a, - int256 b, - string memory message - ) public returns (bool result) { - result = (a == b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: notEqual(int) - - Assert that two (256 bit) signed integers are not equal. - - : A != B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - int256 a, - int256 b, - string memory message - ) public returns (bool result) { - result = (a != b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAbove(int) - - Assert that the int 'A' is greater than the int 'B'. - - : A > B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAbove( - int256 a, - int256 b, - string memory message - ) public returns (bool result) { - result = (a > b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAtLeast(int) - - Assert that the int 'A' is greater than or equal to the int 'B'. - - : A >= B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAtLeast( - int256 a, - int256 b, - string memory message - ) public returns (bool result) { - result = (a >= b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isBelow(int) - - Assert that the int 'A' is lesser than the int 'B'. - - : A < B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isBelow( - int256 a, - int256 b, - string memory message - ) public returns (bool result) { - result = (a < b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAtMost(int) - - Assert that the int 'A' is lesser than or equal to the int 'B'. - - : A <= B - - Params: - A (int) - The first int. - B (int) - The second int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAtMost( - int256 a, - int256 b, - string memory message - ) public returns (bool result) { - result = (a <= b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isZero(int) - - Assert that a (256 bit) signed integer is 0. - - : number == 0 - - Params: - number (int) - The int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isZero(int256 number, string memory message) public returns (bool result) { - result = (number == 0); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(number, "Tested"), message)); - } - - /* - Function: isNotZero(int) - - Assert that a (256 bit) signed integer is not 0. - - : number != 0 - - Params: - number (int) - The int. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isNotZero(int256 number, string memory message) public returns (bool result) { - result = (number != 0); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(number, "Tested"), message)); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } - - /* - Function: _itoa - Convert a signed integer to a string. Negative numbers gets a '-' in front, e.g. "-54". - Params: - n (int) - The integer. - radix (uint8) - A number between 2 and 16 (inclusive). Characters used are 0-9,a-f - Returns: - result (string) - The resulting string. - */ - function _itoa(int256 n, uint8 radix) internal pure returns (string memory) { - if (n == 0 || radix < 2 || radix > 16) return "0"; - bytes memory bts = new bytes(256); - uint256 i; - bool neg = false; - if (n < 0) { - n = -n; - neg = true; - } - while (n > 0) { - bts[i++] = _utoa(uint8(uint256(n) % radix)); // Turn it to ascii. - n = int256(uint256(n) / radix); - } - // Reverse - uint256 size = i; - uint256 j = 0; - bytes memory rev; - if (neg) { - size++; - j = 1; - rev = new bytes(size); - rev[0] = MINUS; - } else rev = new bytes(size); - - for (; j < size; j++) rev[j] = bts[size - j - 1]; - return string(rev); - } - - /* - Function: _utoa(uint8) - - Convert an unsigned 8-bit integer to its ASCII byte representation. Numbers 0-9 are converted to '0'-'9', - numbers 10-16 to 'a'-'f'. Numbers larger then 16 return the null byte. - - Params: - u (uint8) - The unsigned 8-bit integer. - - Returns: - result (string) - The ASCII byte. - */ - function _utoa(uint8 u) internal pure returns (bytes1) { - if (u < 10) return bytes1(u + ZERO); - else if (u < 16) return bytes1(u - 10 + A); - else return 0; - } - - /* - function htoa(address addr) constant returns (string) { - bytes memory bts = new bytes(40); - bytes20 addrBts = bytes20(addr); - for (uint i = 0; i < 20; i++) { - bts[2*i] = addrBts[i] % 16; - bts[2*i + 1] = (addrBts[i] / 16) % 16; - } - return string(bts); - } - */ - - /* - Function: _tag(string) - - Add a tag to a string. The 'value' and 'tag' strings are returned on the form "tag: value". - - Params: - value (string) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: value" - */ - function _tag(string memory value, string memory tag) internal pure returns (string memory) { - bytes memory valueB = bytes(value); - bytes memory tagB = bytes(tag); - - uint256 vl = valueB.length; - uint256 tl = tagB.length; - - bytes memory newB = new bytes(vl + tl + 2); - - uint256 i; - uint256 j; - - for (i = 0; i < tl; i++) newB[j++] = tagB[i]; - newB[j++] = ":"; - newB[j++] = " "; - for (i = 0; i < vl; i++) newB[j++] = valueB[i]; - - return string(newB); - } - - /* - Function: _tag(int) - - Add a tag to an int. - - Params: - value (int) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: _itoa(value)" - */ - function _tag(int256 value, string memory tag) internal pure returns (string memory) { - string memory nstr = _itoa(value, 10); - return _tag(nstr, tag); - } - - /* - Function: _appendTagged(string) - - Append a tagged value to a string. - - Params: - tagged (string) - The tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged)" - */ - function _appendTagged(string memory tagged, string memory str) internal pure returns (string memory) { - bytes memory taggedB = bytes(tagged); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 tl = taggedB.length; - - bytes memory newB = new bytes(sl + tl + 3); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < tl; i++) newB[j++] = taggedB[i]; - newB[j++] = ")"; - - return string(newB); - } - - /* - Function: _appendTagged(string, string) - - Append two tagged values to a string. - - Params: - tagged0 (string) - The first tagged value. - tagged1 (string) - The second tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged0, tagged1)" - */ - function _appendTagged( - string memory tagged0, - string memory tagged1, - string memory str - ) internal pure returns (string memory) { - bytes memory tagged0B = bytes(tagged0); - bytes memory tagged1B = bytes(tagged1); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 t0l = tagged0B.length; - uint256 t1l = tagged1B.length; - - bytes memory newB = new bytes(sl + t0l + t1l + 5); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < t0l; i++) newB[j++] = tagged0B[i]; - newB[j++] = ","; - newB[j++] = " "; - for (i = 0; i < t1l; i++) newB[j++] = tagged1B[i]; - newB[j++] = ")"; - - return string(newB); - } -} diff --git a/contracts/test/helpers/truffle/AssertIntArray.sol b/contracts/test/helpers/truffle/AssertIntArray.sol deleted file mode 100644 index 9de4a7d6..00000000 --- a/contracts/test/helpers/truffle/AssertIntArray.sol +++ /dev/null @@ -1,351 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertIntArray { - uint8 constant ZERO = uint8(bytes1("0")); - uint8 constant A = uint8(bytes1("a")); - - bytes1 constant MINUS = bytes1("-"); - - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** int[] ************************************** - - /* - Function: equal(int[]) - - Assert that two 'int[]' are equal. - - : arrA.length == arrB.length - - and, for all valid indices 'i' - - : arrA[i] == arrB[i] - - Params: - A (int[]) - The first array. - B (int[]) - The second array. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - int256[] memory arrA, - int256[] memory arrB, - string memory message - ) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint256 i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - _report(result, message); - } - - /* - Function: notEqual(int[]) - - Assert that two 'int[]' are not equal. - - : arrA.length != arrB.length - - or, for some valid index 'i' - - : arrA[i] != arrB[i] - - Params: - A (int[]) - The first string. - B (int[]) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - int256[] memory arrA, - int256[] memory arrB, - string memory message - ) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint256 i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - result = !result; - _report(result, message); - } - - /* - Function: lengthEqual(int[]) - - Assert that the length of an 'int[]' is equal to a given value. - - : arr.length == length - - Params: - arr (int[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthEqual( - int256[] memory arr, - uint256 length, - string memory message - ) public returns (bool result) { - uint256 arrLength = arr.length; - if (arrLength == length) _report(result, ""); - else _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /* - Function: lengthNotEqual(int[]) - - Assert that the length of an 'int[]' is not equal to a given value. - - : arr.length != length - - Params: - arr (int[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthNotEqual( - int256[] memory arr, - uint256 length, - string memory message - ) public returns (bool result) { - uint256 arrLength = arr.length; - if (arrLength != arr.length) _report(result, ""); - else _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } - - /* - Function: _itoa - Convert a signed integer to a string. Negative numbers gets a '-' in front, e.g. "-54". - Params: - n (int) - The integer. - radix (uint8) - A number between 2 and 16 (inclusive). Characters used are 0-9,a-f - Returns: - result (string) - The resulting string. - */ - function _itoa(int256 n, uint8 radix) internal pure returns (string memory) { - if (n == 0 || radix < 2 || radix > 16) return "0"; - bytes memory bts = new bytes(256); - uint256 i; - bool neg = false; - if (n < 0) { - n = -n; - neg = true; - } - while (n > 0) { - bts[i++] = _utoa(uint8(uint256(n) % radix)); // Turn it to ascii. - n = int256(uint256(n) / radix); - } - // Reverse - uint256 size = i; - uint256 j = 0; - bytes memory rev; - if (neg) { - size++; - j = 1; - rev = new bytes(size); - rev[0] = MINUS; - } else rev = new bytes(size); - - for (; j < size; j++) rev[j] = bts[size - j - 1]; - return string(rev); - } - - /* - Function: _utoa(uint) - - Convert an unsigned integer to a string. - - Params: - n (uint) - The unsigned integer. - radix (uint8) - A number between 2 and 16 (inclusive). Characters used are 0-9,a-f - - Returns: - result (string) - The resulting string. - */ - function _utoa(uint256 n, uint8 radix) internal pure returns (string memory) { - if (n == 0 || radix < 2 || radix > 16) return "0"; - bytes memory bts = new bytes(256); - uint256 i; - while (n > 0) { - bts[i++] = _utoa(uint8(n % radix)); // Turn it to ascii. - n /= radix; - } - // Reverse - bytes memory rev = new bytes(i); - for (uint256 j = 0; j < i; j++) rev[j] = bts[i - j - 1]; - return string(rev); - } - - /* - Function: _utoa(uint8) - - Convert an unsigned 8-bit integer to its ASCII byte representation. Numbers 0-9 are converted to '0'-'9', - numbers 10-16 to 'a'-'f'. Numbers larger then 16 return the null byte. - - Params: - u (uint8) - The unsigned 8-bit integer. - - Returns: - result (string) - The ASCII byte. - */ - function _utoa(uint8 u) internal pure returns (bytes1) { - if (u < 10) return bytes1(u + ZERO); - else if (u < 16) return bytes1(u - 10 + A); - else return 0; - } - - /* - Function: _tag(string) - - Add a tag to a string. The 'value' and 'tag' strings are returned on the form "tag: value". - - Params: - value (string) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: value" - */ - function _tag(string memory value, string memory tag) internal pure returns (string memory) { - bytes memory valueB = bytes(value); - bytes memory tagB = bytes(tag); - - uint256 vl = valueB.length; - uint256 tl = tagB.length; - - bytes memory newB = new bytes(vl + tl + 2); - - uint256 i; - uint256 j; - - for (i = 0; i < tl; i++) newB[j++] = tagB[i]; - newB[j++] = ":"; - newB[j++] = " "; - for (i = 0; i < vl; i++) newB[j++] = valueB[i]; - - return string(newB); - } - - /* - Function: _tag(int) - - Add a tag to an int. - - Params: - value (int) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: _itoa(value)" - */ - function _tag(int256 value, string memory tag) internal pure returns (string memory) { - string memory nstr = _itoa(value, 10); - return _tag(nstr, tag); - } - - /* - Function: _tag(uint) - - Add a tag to an uint. - - Params: - value (uint) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: _utoa(value)" - */ - function _tag(uint256 value, string memory tag) internal pure returns (string memory) { - string memory nstr = _utoa(value, 10); - return _tag(nstr, tag); - } - - /* - Function: _appendTagged(string, string) - - Append two tagged values to a string. - - Params: - tagged0 (string) - The first tagged value. - tagged1 (string) - The second tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged0, tagged1)" - */ - function _appendTagged( - string memory tagged0, - string memory tagged1, - string memory str - ) internal pure returns (string memory) { - bytes memory tagged0B = bytes(tagged0); - bytes memory tagged1B = bytes(tagged1); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 t0l = tagged0B.length; - uint256 t1l = tagged1B.length; - - bytes memory newB = new bytes(sl + t0l + t1l + 5); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < t0l; i++) newB[j++] = tagged0B[i]; - newB[j++] = ","; - newB[j++] = " "; - for (i = 0; i < t1l; i++) newB[j++] = tagged1B[i]; - newB[j++] = ")"; - - return string(newB); - } -} diff --git a/contracts/test/helpers/truffle/AssertString.sol b/contracts/test/helpers/truffle/AssertString.sol deleted file mode 100644 index 4bdf9575..00000000 --- a/contracts/test/helpers/truffle/AssertString.sol +++ /dev/null @@ -1,259 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertString { - // Constant: STRING_NULL - // The null string: "" - string constant STRING_NULL = ""; - - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** strings ************************************** - - /* - Function: equal(string) - - Assert that two strings are equal. - - : _stringsEqual(A, B) == true - - Params: - A (string) - The first string. - B (string) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - string memory a, - string memory b, - string memory message - ) public returns (bool result) { - result = _stringsEqual(a, b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: notEqual(string) - - Assert that two strings are not equal. - - : _stringsEqual(A, B) == false - - Params: - A (string) - The first string. - B (string) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - string memory a, - string memory b, - string memory message - ) public returns (bool result) { - result = !_stringsEqual(a, b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isEmpty(string) - - Assert that a string is empty. - - : _stringsEqual(str, STRING_NULL) == true - - Params: - str (string) - The string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isEmpty(string memory str, string memory message) public returns (bool result) { - result = _stringsEqual(str, STRING_NULL); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(str, "Tested"), message)); - } - - /* - Function: isNotEmpty(string) - - Assert that a string is not empty. - - : _stringsEqual(str, STRING_NULL) == false - - Params: - str (string) - The string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isNotEmpty(string memory str, string memory message) public returns (bool result) { - result = !_stringsEqual(str, STRING_NULL); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(str, "Tested"), message)); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } - - /* - Function: _stringsEqual - - Compares two strings. Taken from the StringUtils contract in the Ethereum Dapp-bin - (https://github.com/ethereum/dapp-bin/blob/master/library/stringUtils.sol). - - Params: - a (string) - The first string. - b (string) - The second string. - - Returns: - result (bool) - 'true' if the strings are equal, otherwise 'false'. - */ - function _stringsEqual(string memory a, string memory b) internal pure returns (bool result) { - bytes memory ba = bytes(a); - bytes memory bb = bytes(b); - - if (ba.length != bb.length) return false; - for (uint256 i = 0; i < ba.length; i++) { - if (ba[i] != bb[i]) return false; - } - return true; - } - - /* - Function: _tag(string) - - Add a tag to a string. The 'value' and 'tag' strings are returned on the form "tag: value". - - Params: - value (string) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: value" - */ - function _tag(string memory value, string memory tag) internal pure returns (string memory) { - bytes memory valueB = bytes(value); - bytes memory tagB = bytes(tag); - - uint256 vl = valueB.length; - uint256 tl = tagB.length; - - bytes memory newB = new bytes(vl + tl + 2); - - uint256 i; - uint256 j; - - for (i = 0; i < tl; i++) newB[j++] = tagB[i]; - newB[j++] = ":"; - newB[j++] = " "; - for (i = 0; i < vl; i++) newB[j++] = valueB[i]; - - return string(newB); - } - - /* - Function: _appendTagged(string) - - Append a tagged value to a string. - - Params: - tagged (string) - The tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged)" - */ - function _appendTagged(string memory tagged, string memory str) internal pure returns (string memory) { - bytes memory taggedB = bytes(tagged); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 tl = taggedB.length; - - bytes memory newB = new bytes(sl + tl + 3); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < tl; i++) newB[j++] = taggedB[i]; - newB[j++] = ")"; - - return string(newB); - } - - /* - Function: _appendTagged(string, string) - - Append two tagged values to a string. - - Params: - tagged0 (string) - The first tagged value. - tagged1 (string) - The second tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged0, tagged1)" - */ - function _appendTagged( - string memory tagged0, - string memory tagged1, - string memory str - ) internal pure returns (string memory) { - bytes memory tagged0B = bytes(tagged0); - bytes memory tagged1B = bytes(tagged1); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 t0l = tagged0B.length; - uint256 t1l = tagged1B.length; - - bytes memory newB = new bytes(sl + t0l + t1l + 5); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < t0l; i++) newB[j++] = tagged0B[i]; - newB[j++] = ","; - newB[j++] = " "; - for (i = 0; i < t1l; i++) newB[j++] = tagged1B[i]; - newB[j++] = ")"; - - return string(newB); - } -} diff --git a/contracts/test/helpers/truffle/AssertUint.sol b/contracts/test/helpers/truffle/AssertUint.sol deleted file mode 100644 index 06d11f09..00000000 --- a/contracts/test/helpers/truffle/AssertUint.sol +++ /dev/null @@ -1,407 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertUint { - uint8 constant ZERO = uint8(bytes1("0")); - uint8 constant A = uint8(bytes1("a")); - - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** uint ************************************** - - /* - Function: equal(uint) - - Assert that two (256 bit) unsigned integers are equal. - - : A == B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - uint256 a, - uint256 b, - string memory message - ) public returns (bool result) { - result = (a == b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: notEqual(uint) - - Assert that two (256 bit) unsigned integers are not equal. - - : A != B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - uint256 a, - uint256 b, - string memory message - ) public returns (bool result) { - result = (a != b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAbove(uint) - - Assert that the uint 'A' is greater than the uint 'B'. - - : A > B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAbove( - uint256 a, - uint256 b, - string memory message - ) public returns (bool result) { - result = (a > b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAtLeast(uint) - - Assert that the uint 'A' is greater than or equal to the uint 'B'. - - : A >= B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAtLeast( - uint256 a, - uint256 b, - string memory message - ) public returns (bool result) { - result = (a >= b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isBelow(uint) - - Assert that the uint 'A' is lesser than the uint 'B'. - - : A < B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isBelow( - uint256 a, - uint256 b, - string memory message - ) public returns (bool result) { - result = (a < b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isAtMost(uint) - - Assert that the uint 'A' is lesser than or equal to the uint 'B'. - - : A <= B - - Params: - A (uint) - The first uint. - B (uint) - The second uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isAtMost( - uint256 a, - uint256 b, - string memory message - ) public returns (bool result) { - result = (a <= b); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(a, "Tested"), _tag(b, "Against"), message)); - } - - /* - Function: isZero(uint) - - Assert that a (256 bit) unsigned integer is 0. - - : number == 0 - - Params: - number (uint) - The uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isZero(uint256 number, string memory message) public returns (bool result) { - result = (number == 0); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(number, "Tested"), message)); - } - - /* - Function: isNotZero(uint) - - Assert that a (256 bit) unsigned integer is not 0. - - : number != 0 - - Params: - number (uint) - The uint. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function isNotZero(uint256 number, string memory message) public returns (bool result) { - result = (number != 0); - if (result) _report(result, message); - else _report(result, _appendTagged(_tag(number, "Tested"), message)); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } - - /* - Function: _utoa(uint) - - Convert an unsigned integer to a string. - - Params: - n (uint) - The unsigned integer. - radix (uint8) - A number between 2 and 16 (inclusive). Characters used are 0-9,a-f - - Returns: - result (string) - The resulting string. - */ - function _utoa(uint256 n, uint8 radix) internal pure returns (string memory) { - if (n == 0 || radix < 2 || radix > 16) return "0"; - bytes memory bts = new bytes(256); - uint256 i; - while (n > 0) { - bts[i++] = _utoa(uint8(n % radix)); // Turn it to ascii. - n /= radix; - } - // Reverse - bytes memory rev = new bytes(i); - for (uint256 j = 0; j < i; j++) rev[j] = bts[i - j - 1]; - return string(rev); - } - - /* - Function: _utoa(uint8) - - Convert an unsigned 8-bit integer to its ASCII byte representation. Numbers 0-9 are converted to '0'-'9', - numbers 10-16 to 'a'-'f'. Numbers larger then 16 return the null byte. - - Params: - u (uint8) - The unsigned 8-bit integer. - - Returns: - result (string) - The ASCII byte. - */ - function _utoa(uint8 u) internal pure returns (bytes1) { - if (u < 10) return bytes1(u + ZERO); - else if (u < 16) return bytes1(u - 10 + A); - else return 0; - } - - /* - function htoa(address addr) constant returns (string) { - bytes memory bts = new bytes(40); - bytes20 addrBts = bytes20(addr); - for (uint i = 0; i < 20; i++) { - bts[2*i] = addrBts[i] % 16; - bts[2*i + 1] = (addrBts[i] / 16) % 16; - } - return string(bts); - } - */ - - /* - Function: _tag(string) - - Add a tag to a string. The 'value' and 'tag' strings are returned on the form "tag: value". - - Params: - value (string) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: value" - */ - function _tag(string memory value, string memory tag) internal pure returns (string memory) { - bytes memory valueB = bytes(value); - bytes memory tagB = bytes(tag); - - uint256 vl = valueB.length; - uint256 tl = tagB.length; - - bytes memory newB = new bytes(vl + tl + 2); - - uint256 i; - uint256 j; - - for (i = 0; i < tl; i++) newB[j++] = tagB[i]; - newB[j++] = ":"; - newB[j++] = " "; - for (i = 0; i < vl; i++) newB[j++] = valueB[i]; - - return string(newB); - } - - /* - Function: _tag(uint) - - Add a tag to an uint. - - Params: - value (uint) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: _utoa(value)" - */ - function _tag(uint256 value, string memory tag) internal pure returns (string memory) { - string memory nstr = _utoa(value, 10); - return _tag(nstr, tag); - } - - /* - Function: _appendTagged(string) - - Append a tagged value to a string. - - Params: - tagged (string) - The tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged)" - */ - function _appendTagged(string memory tagged, string memory str) internal pure returns (string memory) { - bytes memory taggedB = bytes(tagged); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 tl = taggedB.length; - - bytes memory newB = new bytes(sl + tl + 3); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < tl; i++) newB[j++] = taggedB[i]; - newB[j++] = ")"; - - return string(newB); - } - - /* - Function: _appendTagged(string, string) - - Append two tagged values to a string. - - Params: - tagged0 (string) - The first tagged value. - tagged1 (string) - The second tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged0, tagged1)" - */ - function _appendTagged( - string memory tagged0, - string memory tagged1, - string memory str - ) internal pure returns (string memory) { - bytes memory tagged0B = bytes(tagged0); - bytes memory tagged1B = bytes(tagged1); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 t0l = tagged0B.length; - uint256 t1l = tagged1B.length; - - bytes memory newB = new bytes(sl + t0l + t1l + 5); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < t0l; i++) newB[j++] = tagged0B[i]; - newB[j++] = ","; - newB[j++] = " "; - for (i = 0; i < t1l; i++) newB[j++] = tagged1B[i]; - newB[j++] = ")"; - - return string(newB); - } -} diff --git a/contracts/test/helpers/truffle/AssertUintArray.sol b/contracts/test/helpers/truffle/AssertUintArray.sol deleted file mode 100644 index 0b8b2122..00000000 --- a/contracts/test/helpers/truffle/AssertUintArray.sol +++ /dev/null @@ -1,340 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity 0.8.9; - -library AssertUintArray { - uint8 constant ZERO = uint8(bytes1("0")); - uint8 constant A = uint8(bytes1("a")); - - /* - Event: TestEvent - - Fired when an assertion is made. - - Params: - result (bool) - Whether or not the assertion holds. - message (string) - A message to display if the assertion does not hold. - */ - event TestEvent(bool indexed result, string message); - - // ************************************** uint[] ************************************** - - /* - Function: equal(uint[]) - - Assert that two 'uint[ ]' are equal. - - : arrA.length == arrB.length - - and, for all valid indices 'i' - - : arrA[i] == arrB[i] - - Params: - A (uint[]) - The first array. - B (uint[]) - The second array. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function equal( - uint256[] memory arrA, - uint256[] memory arrB, - string memory message - ) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint256 i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - _report(result, message); - } - - /* - Function: notEqual(uint[]) - - Assert that two 'uint[]' are not equal. - - : arrA.length != arrB.length - - or, for some valid index 'i' - - : arrA[i] != arrB[i] - - Params: - A (uint[]) - The first string. - B (uint[]) - The second string. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function notEqual( - uint256[] memory arrA, - uint256[] memory arrB, - string memory message - ) public returns (bool result) { - result = arrA.length == arrB.length; - if (result) { - for (uint256 i = 0; i < arrA.length; i++) { - if (arrA[i] != arrB[i]) { - result = false; - break; - } - } - } - result = !result; - _report(result, message); - } - - /* - Function: lengthEqual(uint[]) - - Assert that the length of a 'uint[]' is equal to a given value. - - : arr.length == length - - Params: - arr (uint[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthEqual( - uint256[] memory arr, - uint256 length, - string memory message - ) public returns (bool result) { - uint256 arrLength = arr.length; - if (arrLength == length) _report(result, ""); - else _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /* - Function: lengthNotEqual(uint[]) - - Assert that the length of a 'uint[]' is not equal to a given value. - - : arr.length != length - - Params: - arr (uint[]) - The array. - length (uint) - The length. - message (string) - A message that is sent if the assertion fails. - - Returns: - result (bool) - The result. - */ - function lengthNotEqual( - uint256[] memory arr, - uint256 length, - string memory message - ) public returns (bool result) { - uint256 arrLength = arr.length; - if (arrLength != arr.length) _report(result, ""); - else _report(result, _appendTagged(_tag(arrLength, "Tested"), _tag(length, "Against"), message)); - } - - /******************************** internal ********************************/ - - /* - Function: _report - - Internal function for triggering . - - Params: - result (bool) - The test result (true or false). - message (string) - The message that is sent if the assertion fails. - */ - function _report(bool result, string memory message) internal { - if (result) emit TestEvent(true, ""); - else emit TestEvent(false, message); - } - - /* - Function: _utoa(uint) - - Convert an unsigned integer to a string. - - Params: - n (uint) - The unsigned integer. - radix (uint8) - A number between 2 and 16 (inclusive). Characters used are 0-9,a-f - - Returns: - result (string) - The resulting string. - */ - function _utoa(uint256 n, uint8 radix) internal pure returns (string memory) { - if (n == 0 || radix < 2 || radix > 16) return "0"; - bytes memory bts = new bytes(256); - uint256 i; - while (n > 0) { - bts[i++] = _utoa(uint8(n % radix)); // Turn it to ascii. - n /= radix; - } - // Reverse - bytes memory rev = new bytes(i); - for (uint256 j = 0; j < i; j++) rev[j] = bts[i - j - 1]; - return string(rev); - } - - /* - Function: _utoa(uint8) - - Convert an unsigned 8-bit integer to its ASCII byte representation. Numbers 0-9 are converted to '0'-'9', - numbers 10-16 to 'a'-'f'. Numbers larger then 16 return the null byte. - - Params: - u (uint8) - The unsigned 8-bit integer. - - Returns: - result (string) - The ASCII byte. - */ - function _utoa(uint8 u) internal pure returns (bytes1) { - if (u < 10) return bytes1(u + ZERO); - else if (u < 16) return bytes1(u - 10 + A); - else return 0; - } - - /* - function htoa(address addr) constant returns (string) { - bytes memory bts = new bytes(40); - bytes20 addrBts = bytes20(addr); - for (uint i = 0; i < 20; i++) { - bts[2*i] = addrBts[i] % 16; - bts[2*i + 1] = (addrBts[i] / 16) % 16; - } - return string(bts); - } - */ - - /* - Function: _tag(string) - - Add a tag to a string. The 'value' and 'tag' strings are returned on the form "tag: value". - - Params: - value (string) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: value" - */ - function _tag(string memory value, string memory tag) internal pure returns (string memory) { - bytes memory valueB = bytes(value); - bytes memory tagB = bytes(tag); - - uint256 vl = valueB.length; - uint256 tl = tagB.length; - - bytes memory newB = new bytes(vl + tl + 2); - - uint256 i; - uint256 j; - - for (i = 0; i < tl; i++) newB[j++] = tagB[i]; - newB[j++] = ":"; - newB[j++] = " "; - for (i = 0; i < vl; i++) newB[j++] = valueB[i]; - - return string(newB); - } - - /* - Function: _tag(uint) - - Add a tag to an uint. - - Params: - value (uint) - The value. - tag (string) - The tag. - - Returns: - result (string) - "tag: _utoa(value)" - */ - function _tag(uint256 value, string memory tag) internal pure returns (string memory) { - string memory nstr = _utoa(value, 10); - return _tag(nstr, tag); - } - - /* - Function: _appendTagged(string) - - Append a tagged value to a string. - - Params: - tagged (string) - The tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged)" - */ - function _appendTagged(string memory tagged, string memory str) internal pure returns (string memory) { - bytes memory taggedB = bytes(tagged); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 tl = taggedB.length; - - bytes memory newB = new bytes(sl + tl + 3); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < tl; i++) newB[j++] = taggedB[i]; - newB[j++] = ")"; - - return string(newB); - } - - /* - Function: _appendTagged(string, string) - - Append two tagged values to a string. - - Params: - tagged0 (string) - The first tagged value. - tagged1 (string) - The second tagged value. - str (string) - The string. - - Returns: - result (string) - "str (tagged0, tagged1)" - */ - function _appendTagged( - string memory tagged0, - string memory tagged1, - string memory str - ) internal pure returns (string memory) { - bytes memory tagged0B = bytes(tagged0); - bytes memory tagged1B = bytes(tagged1); - bytes memory strB = bytes(str); - - uint256 sl = strB.length; - uint256 t0l = tagged0B.length; - uint256 t1l = tagged1B.length; - - bytes memory newB = new bytes(sl + t0l + t1l + 5); - - uint256 i; - uint256 j; - - for (i = 0; i < sl; i++) newB[j++] = strB[i]; - newB[j++] = " "; - newB[j++] = "("; - for (i = 0; i < t0l; i++) newB[j++] = tagged0B[i]; - newB[j++] = ","; - newB[j++] = " "; - for (i = 0; i < t1l; i++) newB[j++] = tagged1B[i]; - newB[j++] = ")"; - - return string(newB); - } -} From 97659b7a481e4f94e996fcb77ae295364affaaf8 Mon Sep 17 00:00:00 2001 From: RiccardoBiosas Date: Wed, 13 Jul 2022 06:48:11 -0500 Subject: [PATCH 5/5] tests(foundry): Moved RevertProxy contract from truffle directory to foundry --- {contracts => src}/test/helpers/RevertProxy.sol | 0 src/test/unit/TestMathUtils.sol | 2 +- src/test/unit/TestSortedDoublyLLFindWithHints.sol | 2 +- src/test/unit/TestSortedDoublyLLFindWithHintsV2.sol | 2 +- src/test/unit/TestSortedDoublyLLInsert.sol | 4 ++-- src/test/unit/TestSortedDoublyLLRemove.sol | 4 ++-- src/test/unit/TestSortedDoublyLLUpdateKey.sol | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) rename {contracts => src}/test/helpers/RevertProxy.sol (100%) diff --git a/contracts/test/helpers/RevertProxy.sol b/src/test/helpers/RevertProxy.sol similarity index 100% rename from contracts/test/helpers/RevertProxy.sol rename to src/test/helpers/RevertProxy.sol diff --git a/src/test/unit/TestMathUtils.sol b/src/test/unit/TestMathUtils.sol index 29ced695..939e25ea 100644 --- a/src/test/unit/TestMathUtils.sol +++ b/src/test/unit/TestMathUtils.sol @@ -2,8 +2,8 @@ pragma solidity 0.8.9; import "ds-test/test.sol"; -import "../interfaces/ICheatCodes.sol"; import "contracts/libraries/MathUtils.sol"; +import "../interfaces/ICheatCodes.sol"; contract TestMathUtils is DSTest { ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); diff --git a/src/test/unit/TestSortedDoublyLLFindWithHints.sol b/src/test/unit/TestSortedDoublyLLFindWithHints.sol index bac94a4d..15b6f521 100644 --- a/src/test/unit/TestSortedDoublyLLFindWithHints.sol +++ b/src/test/unit/TestSortedDoublyLLFindWithHints.sol @@ -2,8 +2,8 @@ pragma solidity 0.8.9; import "ds-test/test.sol"; -import "../interfaces/ICheatCodes.sol"; import "contracts/test/mocks/SortedDoublyLLFixture.sol"; +import "../interfaces/ICheatCodes.sol"; contract TestSortedDoublyLLFindWithHints is DSTest { ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); diff --git a/src/test/unit/TestSortedDoublyLLFindWithHintsV2.sol b/src/test/unit/TestSortedDoublyLLFindWithHintsV2.sol index c6bdb296..71d530b9 100644 --- a/src/test/unit/TestSortedDoublyLLFindWithHintsV2.sol +++ b/src/test/unit/TestSortedDoublyLLFindWithHintsV2.sol @@ -2,8 +2,8 @@ pragma solidity 0.8.9; import "ds-test/test.sol"; -import "../interfaces/ICheatCodes.sol"; import "contracts/test/mocks/SortedDoublyLLFixture.sol"; +import "../interfaces/ICheatCodes.sol"; contract TestSortedDoublyLLFindWithHintsV2 is DSTest { ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); diff --git a/src/test/unit/TestSortedDoublyLLInsert.sol b/src/test/unit/TestSortedDoublyLLInsert.sol index 6b3b9c97..c1c76faa 100644 --- a/src/test/unit/TestSortedDoublyLLInsert.sol +++ b/src/test/unit/TestSortedDoublyLLInsert.sol @@ -2,9 +2,9 @@ pragma solidity 0.8.9; import "ds-test/test.sol"; -import "../interfaces/ICheatCodes.sol"; import "contracts/test/mocks/SortedDoublyLLFixture.sol"; -import "contracts/test/helpers/RevertProxy.sol"; +import "../helpers/RevertProxy.sol"; +import "../interfaces/ICheatCodes.sol"; contract TestSortedDoublyLLInsert is DSTest { ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); diff --git a/src/test/unit/TestSortedDoublyLLRemove.sol b/src/test/unit/TestSortedDoublyLLRemove.sol index e9f91e95..8df387e7 100644 --- a/src/test/unit/TestSortedDoublyLLRemove.sol +++ b/src/test/unit/TestSortedDoublyLLRemove.sol @@ -2,9 +2,9 @@ pragma solidity 0.8.9; import "ds-test/test.sol"; -import "../interfaces/ICheatCodes.sol"; import "contracts/test/mocks/SortedDoublyLLFixture.sol"; -import "contracts/test/helpers/RevertProxy.sol"; +import "../helpers/RevertProxy.sol"; +import "../interfaces/ICheatCodes.sol"; contract TestSortedDoublyLLRemove is DSTest { ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS); diff --git a/src/test/unit/TestSortedDoublyLLUpdateKey.sol b/src/test/unit/TestSortedDoublyLLUpdateKey.sol index e2b3cb1c..9536e86a 100644 --- a/src/test/unit/TestSortedDoublyLLUpdateKey.sol +++ b/src/test/unit/TestSortedDoublyLLUpdateKey.sol @@ -2,9 +2,9 @@ pragma solidity 0.8.9; import "ds-test/test.sol"; -import "../interfaces/ICheatCodes.sol"; import "contracts/test/mocks/SortedDoublyLLFixture.sol"; -import "contracts/test/helpers/RevertProxy.sol"; +import "../helpers/RevertProxy.sol"; +import "../interfaces/ICheatCodes.sol"; contract TestSortedDoublyLLUpdateKey is DSTest { ICheatCodes public constant CHEATS = ICheatCodes(HEVM_ADDRESS);