Skip to content

Commit

Permalink
test: test different array lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaa committed Mar 6, 2024
1 parent b632b7d commit 9e398bf
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion e2e/packages/contracts/test/StaticArray.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,23 @@ import { toStaticArray_uint256_2 } from "../src/codegen/tables/StaticArray.sol";
contract StaticArrayTest is MudTest {
uint256 internal memoryCorruptionCheck = uint256(keccak256("memoryCorruptionCheck"));

function testMemoryCorruption() public {
/*
* Test that the data is correctly copied when the dynamic and static arrays are the same length
*/
function testMemoryCorruptionSameLength() public {
uint256[] memory data = new uint256[](2);
data[0] = 1;
data[1] = 2;

uint256[2] memory result = toStaticArray_uint256_2(data);
assertEq(result[0], 1);
assertEq(result[1], 2);
}

/*
* Test that the data is correctly copied when the dynamic array is longer
*/
function testMemoryCorruptionLongerDynamic() public {
uint256[] memory data = new uint256[](3);
data[0] = 1;
data[1] = 2;
Expand All @@ -25,4 +41,16 @@ contract StaticArrayTest is MudTest {
}
assertEq(memoryAfterResult, memoryCorruptionCheck);
}

/*
* Test that an uninitialized array is returned when the dynamic array is shorter
*/
function testMemoryCorruptionShorterDynamic() public {
uint256[] memory data = new uint256[](1);
data[0] = 1;

uint256[2] memory result = toStaticArray_uint256_2(data);
assertEq(result[0], 0);
assertEq(result[1], 0);
}
}

0 comments on commit 9e398bf

Please sign in to comment.