From df85f5bc6f0f471a8e0da7a5bcff2d2b59375239 Mon Sep 17 00:00:00 2001 From: Rachel Bousfield Date: Thu, 3 Aug 2023 09:11:26 -0600 Subject: [PATCH 1/3] add testcase --- src/mocks/SdkStorage.sol | 94 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/mocks/SdkStorage.sol diff --git a/src/mocks/SdkStorage.sol b/src/mocks/SdkStorage.sol new file mode 100644 index 00000000..7309ef26 --- /dev/null +++ b/src/mocks/SdkStorage.sol @@ -0,0 +1,94 @@ +// Copyright 2022-2023, Offchain Labs, Inc. +// For license information, see https://github.com/nitro/blob/master/LICENSE +// SPDX-License-Identifier: BUSL-1.1 + +pragma solidity ^0.8.0; + +contract SdkStorage { + bool flag; + address owner; + address other; + Struct sub; + Struct[] structs; + uint64[] vector; + uint40[][] nested; + bytes bytesFull; + bytes bytesLong; + string chars; + Maps maps; + + struct Struct { + uint16 num; + int32 other; + bytes32 word; + } + + struct Maps { + mapping(uint256 => address) basic; + mapping(address => bool[]) vects; + mapping(uint32 => address)[] array; + mapping(bytes1 => mapping(bool => uint256)) nested; + mapping(string => Struct) structs; + } + + function test() external { + flag = true; + owner = address(0x70); + other = address(0x30); + + sub.num = 32; + sub.other = type(int32).max; + sub.word = bytes32(uint(64)); + + for (uint64 i = 0; i < 32; i++) { + vector.push(i); + } + vector[7] = 77; + + for (uint w = 0; w < 10; w++) { + nested.push(new uint40[](w)); + for (uint i = 0; i < w; i++) { + nested[w][i] = uint40(i); + } + } + for (uint w = 0; w < 10; w++) { + for (uint i = 0; i < w; i++) { + nested[w][i] *= 2; + } + } + + for (uint8 i = 0; i < 31; i++) { + bytesFull = abi.encodePacked(bytesFull, i); + } + for (uint8 i = 0; i < 34; i++) { + bytesLong = abi.encodePacked(bytesLong, i); + } + chars = "arbitrum stylus"; + + for (uint i = 0; i < 16; i++) { + maps.basic[i] = address(uint160(i)); + } + + for (uint160 a = 0; a < 4; a++) { + maps.vects[address(a)] = new bool[](0); + for (uint i = 0; i <= a; i++) { + maps.vects[address(a)].push(true); + } + } + + for (uint32 i = 0; i < 4; i++) { + maps.array.push(); + maps.array[i][i] = address(uint160(i)); + } + + for (uint8 i = 0; i < 4; i++) { + maps.nested[bytes1(i)][i % 2 == 0] = i + 1; + } + + maps.structs["stylus"] = sub; + + for (uint i = 0; i < 4; i++) { + structs.push(sub); + } + } +} From 58006ac0359c51fa81b15c2c25954cc927a7cfbb Mon Sep 17 00:00:00 2001 From: Rachel Bousfield Date: Sat, 5 Aug 2023 12:34:49 -0600 Subject: [PATCH 2/3] deletion test --- src/mocks/SdkStorage.sol | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/mocks/SdkStorage.sol b/src/mocks/SdkStorage.sol index 7309ef26..da56a207 100644 --- a/src/mocks/SdkStorage.sol +++ b/src/mocks/SdkStorage.sol @@ -26,33 +26,33 @@ contract SdkStorage { struct Maps { mapping(uint256 => address) basic; mapping(address => bool[]) vects; - mapping(uint32 => address)[] array; + mapping(int32 => address)[] array; mapping(bytes1 => mapping(bool => uint256)) nested; mapping(string => Struct) structs; } - function test() external { + function populate() external { flag = true; owner = address(0x70); other = address(0x30); sub.num = 32; sub.other = type(int32).max; - sub.word = bytes32(uint(64)); + sub.word = bytes32(uint256(64)); for (uint64 i = 0; i < 32; i++) { vector.push(i); } vector[7] = 77; - for (uint w = 0; w < 10; w++) { + for (uint256 w = 0; w < 10; w++) { nested.push(new uint40[](w)); - for (uint i = 0; i < w; i++) { + for (uint256 i = 0; i < w; i++) { nested[w][i] = uint40(i); } } - for (uint w = 0; w < 10; w++) { - for (uint i = 0; i < w; i++) { + for (uint256 w = 0; w < 10; w++) { + for (uint256 i = 0; i < w; i++) { nested[w][i] *= 2; } } @@ -65,20 +65,20 @@ contract SdkStorage { } chars = "arbitrum stylus"; - for (uint i = 0; i < 16; i++) { + for (uint256 i = 0; i < 16; i++) { maps.basic[i] = address(uint160(i)); } for (uint160 a = 0; a < 4; a++) { maps.vects[address(a)] = new bool[](0); - for (uint i = 0; i <= a; i++) { + for (uint256 i = 0; i <= a; i++) { maps.vects[address(a)].push(true); } } - for (uint32 i = 0; i < 4; i++) { + for (int32 i = 0; i < 4; i++) { maps.array.push(); - maps.array[i][i] = address(uint160(i)); + maps.array[uint256(uint32(i))][i] = address(uint160(uint32(i))); } for (uint8 i = 0; i < 4; i++) { @@ -87,8 +87,10 @@ contract SdkStorage { maps.structs["stylus"] = sub; - for (uint i = 0; i < 4; i++) { + for (uint256 i = 0; i < 4; i++) { structs.push(sub); } } + + function remove() external {} } From c86ee1c24cd228c67cb4dd023db956f9f6316192 Mon Sep 17 00:00:00 2001 From: Rachel Bousfield Date: Thu, 10 Aug 2023 20:48:27 -0600 Subject: [PATCH 3/3] pop & delete tests --- src/mocks/SdkStorage.sol | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/mocks/SdkStorage.sol b/src/mocks/SdkStorage.sol index da56a207..c90c64d0 100644 --- a/src/mocks/SdkStorage.sol +++ b/src/mocks/SdkStorage.sol @@ -60,7 +60,7 @@ contract SdkStorage { for (uint8 i = 0; i < 31; i++) { bytesFull = abi.encodePacked(bytesFull, i); } - for (uint8 i = 0; i < 34; i++) { + for (uint8 i = 0; i < 80; i++) { bytesLong = abi.encodePacked(bytesLong, i); } chars = "arbitrum stylus"; @@ -92,5 +92,32 @@ contract SdkStorage { } } - function remove() external {} + function remove() external { + while (bytesFull.length != 0) { + bytesFull.pop(); + } + + while (bytesLong.length > 16) { + bytesLong.pop(); + } + + chars = "wasm is cute <3"; + + while (vector.length != 0) { + vector.pop(); + } + + while (nested.length > 1) { + nested.pop(); + } + + for (uint256 i = 0; i < 8; i++) { + delete maps.basic[i]; + } + maps.basic[8] = address(32); + + for (uint160 i = 0; i < 4; i++) { + delete maps.vects[address(i)]; + } + } }