Skip to content

Commit 5ff2cd1

Browse files
committed
test map
1 parent 7ec2d39 commit 5ff2cd1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/CborDecode.t.sol

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,33 @@ contract CborDecodeTest {
154154
(num, index) = input.readUInt8(index);
155155
require(num == 111, "num is not 111");
156156
}
157+
158+
function test_decodeMap() public pure {
159+
bytes memory input = hex"A3616101616202616303";
160+
161+
uint index = 0;
162+
uint mapLen = 0;
163+
(mapLen, index) = input.readFixedMap(index);
164+
require(mapLen == 3, "map len is not 2");
165+
166+
string memory mapKey;
167+
uint8 mapValue;
168+
(mapKey, index) = input.readString(index);
169+
require(keccak256(abi.encodePacked(mapKey)) == keccak256(abi.encodePacked("a")), "map key is not 'a'");
170+
171+
(mapValue, index) = input.readUInt8(index);
172+
require(mapValue == 1, "map value is not 1");
173+
174+
(mapKey, index) = input.readString(index);
175+
require(keccak256(abi.encodePacked(mapKey)) == keccak256(abi.encodePacked("b")), "map key is not 'b'");
176+
177+
(mapValue, index) = input.readUInt8(index);
178+
require(mapValue == 2, "map value is not 2");
179+
180+
(mapKey, index) = input.readString(index);
181+
require(keccak256(abi.encodePacked(mapKey)) == keccak256(abi.encodePacked("c")), "map key is not 'c'");
182+
183+
(mapValue, index) = input.readUInt8(index);
184+
require(mapValue == 3, "map value is not 3");
185+
}
157186
}

0 commit comments

Comments
 (0)