mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Extracting more end-to-end tests.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
contract test {
|
||||
struct topStruct {
|
||||
nestedStruct nstr;
|
||||
uint topValue;
|
||||
mapping (uint => uint) topMapping;
|
||||
}
|
||||
uint toDelete;
|
||||
topStruct str;
|
||||
struct nestedStruct {
|
||||
uint nestedValue;
|
||||
mapping (uint => bool) nestedMapping;
|
||||
}
|
||||
constructor() public {
|
||||
toDelete = 5;
|
||||
str.topValue = 1;
|
||||
str.topMapping[0] = 1;
|
||||
str.topMapping[1] = 2;
|
||||
|
||||
str.nstr.nestedValue = 2;
|
||||
str.nstr.nestedMapping[0] = true;
|
||||
str.nstr.nestedMapping[1] = false;
|
||||
delete str;
|
||||
delete toDelete;
|
||||
}
|
||||
function getToDelete() public returns (uint res){
|
||||
res = toDelete;
|
||||
}
|
||||
function getTopValue() public returns(uint topValue){
|
||||
topValue = str.topValue;
|
||||
}
|
||||
function getNestedValue() public returns(uint nestedValue){
|
||||
nestedValue = str.nstr.nestedValue;
|
||||
}
|
||||
function getTopMapping(uint index) public returns(uint ret) {
|
||||
ret = str.topMapping[index];
|
||||
}
|
||||
function getNestedMapping(uint index) public returns(bool ret) {
|
||||
return str.nstr.nestedMapping[index];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// getToDelete() -> 0
|
||||
// getTopValue() -> 0
|
||||
// getNestedValue() -> 0
|
||||
// #mapping values should be the same#
|
||||
// getTopMapping(uint256): 0 -> 1
|
||||
// getTopMapping(uint256): 1 -> 2
|
||||
// getNestedMapping(uint256): 0 -> true
|
||||
// getNestedMapping(uint256): 1 -> false
|
||||
@@ -0,0 +1,24 @@
|
||||
contract test {
|
||||
struct s2 {
|
||||
uint32 z;
|
||||
mapping(uint8 => s2) recursive;
|
||||
}
|
||||
s2 data;
|
||||
function check() public returns (bool ok) {
|
||||
return data.z == 2 &&
|
||||
data.recursive[0].z == 3 &&
|
||||
data.recursive[0].recursive[1].z == 0 &&
|
||||
data.recursive[0].recursive[0].z == 1;
|
||||
}
|
||||
function set() public {
|
||||
data.z = 2;
|
||||
mapping(uint8 => s2) storage map = data.recursive;
|
||||
s2 storage inner = map[0];
|
||||
inner.z = 3;
|
||||
inner.recursive[0].z = inner.recursive[1].z + 1;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// check() -> false
|
||||
// set() ->
|
||||
// check() -> true
|
||||
@@ -0,0 +1,33 @@
|
||||
contract test {
|
||||
struct s1 {
|
||||
uint8 x;
|
||||
bool y;
|
||||
}
|
||||
struct s2 {
|
||||
uint32 z;
|
||||
s1 s1data;
|
||||
mapping(uint8 => s2) recursive;
|
||||
}
|
||||
s2 data;
|
||||
function check() public returns (bool ok) {
|
||||
return data.z == 1 && data.s1data.x == 2 &&
|
||||
data.s1data.y == true &&
|
||||
data.recursive[3].recursive[4].z == 5 &&
|
||||
data.recursive[4].recursive[3].z == 6 &&
|
||||
data.recursive[0].s1data.y == false &&
|
||||
data.recursive[4].z == 9;
|
||||
}
|
||||
function set() public {
|
||||
data.z = 1;
|
||||
data.s1data.x = 2;
|
||||
data.s1data.y = true;
|
||||
data.recursive[3].recursive[4].z = 5;
|
||||
data.recursive[4].recursive[3].z = 6;
|
||||
data.recursive[0].s1data.y = false;
|
||||
data.recursive[4].z = 9;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// check() -> false
|
||||
// set() ->
|
||||
// check() -> true
|
||||
Reference in New Issue
Block a user