aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-05-28 19:07:04 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-06-08 06:38:47 +0800
commit76b918d40e3bb485cdd45149888f012d9ec2b67f (patch)
tree8a9e47b9db5ffb74e545f2dc3f39a811f0d88f01
parentf5bc0b205c217eac8abdfee9dcdb3c4d21b5c31e (diff)
downloaddexon-sol-tools-76b918d40e3bb485cdd45149888f012d9ec2b67f.tar.gz
dexon-sol-tools-76b918d40e3bb485cdd45149888f012d9ec2b67f.tar.zst
dexon-sol-tools-76b918d40e3bb485cdd45149888f012d9ec2b67f.zip
Convert Solidity tests to vectors
-rw-r--r--packages/contracts/src/contracts/current/test/TestLibMem/TestLibMem.sol203
-rw-r--r--packages/contracts/test/libraries/lib_mem.ts35
2 files changed, 6 insertions, 232 deletions
diff --git a/packages/contracts/src/contracts/current/test/TestLibMem/TestLibMem.sol b/packages/contracts/src/contracts/current/test/TestLibMem/TestLibMem.sol
index 18deede4c..64bc182f4 100644
--- a/packages/contracts/src/contracts/current/test/TestLibMem/TestLibMem.sol
+++ b/packages/contracts/src/contracts/current/test/TestLibMem/TestLibMem.sol
@@ -46,207 +46,4 @@ contract TestLibMem is
// Return modified memory contents
return mem;
}
-
- function test1()
- external
- {
- // Length of array & length to copy
- uint256 length = 0;
-
- // Create source array
- bytes memory sourceArray = new bytes(length);
-
- // Create dest array with same contents as source array
- bytes memory destArray = new bytes(length);
- memcpy(
- getMemAddress(destArray) + 32, // skip copying array length
- getMemAddress(sourceArray) + 32, // skip copying array length
- length
- );
-
- // Verify contents of source & dest arrays match
- require(
- areBytesEqual(sourceArray, destArray),
- "Test #1 failed. Array contents are not the same."
- );
- }
-
- function test2()
- external
- {
- // Length of array & length to copy
- uint256 length = 1;
-
- // Create source array
- bytes memory sourceArray = new bytes(length);
- sourceArray[0] = byte(1);
-
- // Create dest array with same contents as source array
- bytes memory destArray = new bytes(length);
- memcpy(
- getMemAddress(destArray) + 32, // skip copying array length
- getMemAddress(sourceArray) + 32, // skip copying array length
- length
- );
-
- // Verify contents of source & dest arrays match
- require(
- areBytesEqual(sourceArray, destArray),
- "Test #2 failed. Array contents are not the same."
- );
- }
-
- function test3()
- external
- {
- // Length of array & length to copy
- uint256 length = 11;
-
- // Create source array
- bytes memory sourceArray = new bytes(length);
- for(uint256 i = 0; i < length; ++i) {
- sourceArray[i] = byte((i % 0xF) + 1); // [1..f]
- }
-
- // Create dest array with same contents as source array
- bytes memory destArray = new bytes(length);
- memcpy(
- getMemAddress(destArray) + 32, // skip copying array length
- getMemAddress(sourceArray) + 32, // skip copying array length
- length
- );
-
- // Verify contents of source & dest arrays match
- require(
- areBytesEqual(sourceArray, destArray),
- "Test #3 failed. Array contents are not the same."
- );
- }
-
- function test4()
- external
- {
- // Length of array & length to copy
- uint256 length = 32;
-
- // Create source array
- bytes memory sourceArray = new bytes(length);
- for(uint256 i = 0; i < length; ++i) {
- sourceArray[i] = byte((i % 0xF) + 1); // [1..f]
- }
-
- // Create dest array with same contents as source array
- bytes memory destArray = new bytes(length);
- memcpy(
- getMemAddress(destArray) + 32, // skip copying array length
- getMemAddress(sourceArray) + 32, // skip copying array length
- length
- );
-
- // Verify contents of source & dest arrays match
- require(
- areBytesEqual(sourceArray, destArray),
- "Test #4 failed. Array contents are not the same."
- );
- }
-
- function test5()
- external
- {
- // Length of array & length to copy
- uint256 length = 72;
-
- // Create source array
- bytes memory sourceArray = new bytes(length);
- for(uint256 i = 0; i < length; ++i) {
- sourceArray[i] = byte((i % 0xF) + 1); // [1..f]
- }
-
- // Create dest array with same contents as source array
- bytes memory destArray = new bytes(length);
- memcpy(
- getMemAddress(destArray) + 32, // skip copying array length
- getMemAddress(sourceArray) + 32, // skip copying array length
- length
- );
-
- // Verify contents of source & dest arrays match
- require(
- areBytesEqual(sourceArray, destArray),
- "Test #5 failed. Array contents are not the same."
- );
- }
-
-
- function test6()
- external
- {
- // Length of arrays
- uint256 length1 = 72;
- uint256 length2 = 100;
-
- // The full source array is used for comparisons at the end
- bytes memory fullSourceArray = new bytes(length1 + length2);
-
- // First source array
- bytes memory sourceArray1 = new bytes(length1);
- for(uint256 i = 0; i < length1; ++i) {
- sourceArray1[i] = byte((i % 0xF) + 1); // [1..f]
- fullSourceArray[i] = byte((i % 0xF) + 1); // [1..f]
- }
-
- // Second source array
- bytes memory sourceArray2 = new bytes(length2);
- for(uint256 j = 0; i < length2; ++i) {
- sourceArray2[j] = byte((j % 0xF) + 1); // [1..f]
- fullSourceArray[length1+j] = byte((j % 0xF) + 1); // [1..f]
- }
-
- // Create dest array with same contents as source arrays
- bytes memory destArray = new bytes(length1 + length2);
- memcpy(
- getMemAddress(destArray) + 32, // skip copying array length
- getMemAddress(sourceArray1) + 32, // skip copying array length
- length1
- );
- memcpy(
- getMemAddress(destArray) + 32 + length1, // skip copying array length + sourceArray1 bytes
- getMemAddress(sourceArray2) + 32, // skip copying array length
- length2
- );
-
- // Verify contents of source & dest arrays match
- require(
- areBytesEqual(fullSourceArray, destArray),
- "Test #6 failed. Array contents are not the same."
- );
- }
-
- function test7()
- external
- {
- // Length of array & length to copy
- uint256 length = 72;
-
- // Create source array
- bytes memory sourceArray = new bytes(length);
- for(uint256 i = 0; i < length; ++i) {
- sourceArray[i] = byte((i % 0xF) + 1); // [1..f]
- }
-
- // Create dest array with same contents as source array
- bytes memory destArray = new bytes(length);
- memcpy(
- getMemAddress(destArray) + 32, // skip copying array length
- getMemAddress(sourceArray) + 32, // skip copying array length
- length - 8 // Copy all but last byte.
- );
-
- // Verify contents of source & dest arrays match
- // We expect this to fail
- require(
- areBytesEqual(sourceArray, destArray),
- "Test #7 failed. Array contents are not the same. This is expected."
- );
- }
}
diff --git a/packages/contracts/test/libraries/lib_mem.ts b/packages/contracts/test/libraries/lib_mem.ts
index c884d5fea..24f933ad8 100644
--- a/packages/contracts/test/libraries/lib_mem.ts
+++ b/packages/contracts/test/libraries/lib_mem.ts
@@ -57,7 +57,12 @@ describe('LibMem', () => {
// Test vectors: destination, source, length, job description
const tests: Array<[number, number, number, string]> = [
- [1, 5, 4, 'four bytes within one word'],
+ [128, 0, 0, 'zero bytes'],
+ [128, 0, 1, 'one byte'],
+ [128, 0, 11, 'eleven bytes'],
+ [128, 0, 32, 'one word'],
+ [128, 0, 72, 'two words and eight bytes'],
+ [128, 0, 100, 'three words and four bytes']
];
// Construct test cases
@@ -74,33 +79,5 @@ describe('LibMem', () => {
expect(result).to.deep.equal(expected);
}),
);
-
- it('should )', async () => {
- await testLibMem.test1.sendTransactionAsync();
- });
-
- it('should )', async () => {
- await testLibMem.test2.sendTransactionAsync();
- });
-
- it('should )', async () => {
- await testLibMem.test3.sendTransactionAsync();
- });
-
- it('should )', async () => {
- await testLibMem.test4.sendTransactionAsync();
- });
-
- it('should )', async () => {
- await testLibMem.test5.sendTransactionAsync();
- });
-
- it('should )', async () => {
- await testLibMem.test6.sendTransactionAsync();
- });
-
- it('should )', async () => {
- return expect(testLibMem.test7.sendTransactionAsync()).to.be.rejectedWith(constants.REVERT );
- });
});
});