From 76b918d40e3bb485cdd45149888f012d9ec2b67f Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Mon, 28 May 2018 13:07:04 +0200 Subject: Convert Solidity tests to vectors --- .../current/test/TestLibMem/TestLibMem.sol | 203 --------------------- 1 file changed, 203 deletions(-) (limited to 'packages/contracts/src') 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." - ); - } } -- cgit v1.2.3