From e7a05324afad143b9859459e4e7cf1723c1d98d7 Mon Sep 17 00:00:00 2001 From: Djordje Mijovic Date: Wed, 2 Sep 2020 09:36:20 +0200 Subject: [PATCH] Adding simple array copying tests --- .../array/array_copy_memory_to_storage.sol | 11 +++++++++++ .../array/array_copy_storage_to_memory.sol | 10 ++++++++++ .../semanticTests/array/bytes_memory_to_storage.sol | 10 ++++++++++ .../semanticTests/array/bytes_storage_to_memory.sol | 9 +++++++++ .../calldata/calldata_bytes_to_storage.sol | 9 +++++++++ 5 files changed, 49 insertions(+) create mode 100644 test/libsolidity/semanticTests/array/array_copy_memory_to_storage.sol create mode 100644 test/libsolidity/semanticTests/array/array_copy_storage_to_memory.sol create mode 100644 test/libsolidity/semanticTests/array/bytes_memory_to_storage.sol create mode 100644 test/libsolidity/semanticTests/array/bytes_storage_to_memory.sol create mode 100644 test/libsolidity/semanticTests/calldata/calldata_bytes_to_storage.sol diff --git a/test/libsolidity/semanticTests/array/array_copy_memory_to_storage.sol b/test/libsolidity/semanticTests/array/array_copy_memory_to_storage.sol new file mode 100644 index 000000000..3055b0fa8 --- /dev/null +++ b/test/libsolidity/semanticTests/array/array_copy_memory_to_storage.sol @@ -0,0 +1,11 @@ +contract C { + uint[] a; + function f() public returns (uint, uint) { + uint[] memory b = new uint[](3); + b[0] = 1; + a = b; + return (a[0], a.length); + } +} +// ---- +// f() -> 1, 3 diff --git a/test/libsolidity/semanticTests/array/array_copy_storage_to_memory.sol b/test/libsolidity/semanticTests/array/array_copy_storage_to_memory.sol new file mode 100644 index 000000000..8bc6b86a2 --- /dev/null +++ b/test/libsolidity/semanticTests/array/array_copy_storage_to_memory.sol @@ -0,0 +1,10 @@ +contract C { + uint[] a; + function f() public returns (uint, uint) { + a.push(1); a.push(0); a.push(0); + uint[] memory b = a; + return (b[0], b.length); + } +} +// ---- +// f() -> 1, 3 diff --git a/test/libsolidity/semanticTests/array/bytes_memory_to_storage.sol b/test/libsolidity/semanticTests/array/bytes_memory_to_storage.sol new file mode 100644 index 000000000..eebdb7e9b --- /dev/null +++ b/test/libsolidity/semanticTests/array/bytes_memory_to_storage.sol @@ -0,0 +1,10 @@ +contract C { + bytes s; + function f() external returns (byte) { + bytes memory data = "abcd"; + s = data; + return s[0]; + } +} +// ---- +// f() -> "a" diff --git a/test/libsolidity/semanticTests/array/bytes_storage_to_memory.sol b/test/libsolidity/semanticTests/array/bytes_storage_to_memory.sol new file mode 100644 index 000000000..13932a2cc --- /dev/null +++ b/test/libsolidity/semanticTests/array/bytes_storage_to_memory.sol @@ -0,0 +1,9 @@ +contract C { + bytes s = "abcd"; + function f() external returns (byte) { + bytes memory data = s; + return data[0]; + } +} +// ---- +// f() -> "a" diff --git a/test/libsolidity/semanticTests/calldata/calldata_bytes_to_storage.sol b/test/libsolidity/semanticTests/calldata/calldata_bytes_to_storage.sol new file mode 100644 index 000000000..07041910d --- /dev/null +++ b/test/libsolidity/semanticTests/calldata/calldata_bytes_to_storage.sol @@ -0,0 +1,9 @@ +contract C { + bytes s; + function f(bytes calldata data) external returns (byte) { + s = data; + return s[0]; + } +} +// ---- +// f(bytes): 0x20, 0x08, "abcdefgh" -> "a"