mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 20:36:19 +00:00
Tests for mapping with reference type values. (#70)
Co-authored-by: nikugogoi <95nikass@gmail.com>
This commit is contained in:
parent
4e08f359fc
commit
b505332970
@ -68,10 +68,10 @@ $ yarn test
|
||||
* [x] Value Type keys
|
||||
* [ ] Fixed-size byte array keys
|
||||
* [x] Dynamically-sized byte array keys
|
||||
* [ ] Reference Type Mapping values
|
||||
* [x] Reference Type Mapping values
|
||||
* [x] Struct type values
|
||||
* [ ] Array type values
|
||||
* [ ] Dynamically sized Bytes and string type values
|
||||
* [x] Array type values
|
||||
* [x] Dynamically sized Bytes and string type values
|
||||
* [x] Nested Mapping
|
||||
|
||||
## Observations
|
||||
|
@ -1213,6 +1213,53 @@ describe('Get value from storage', () => {
|
||||
const { value } = await getStorageValue(storageLayout, getStorageAt, blockHash, testMappingTypes.address, 'addressStructMap', mapKey);
|
||||
expect(value).to.eql(expectedValue);
|
||||
});
|
||||
|
||||
it('get value for mapping of unsigned integer keys and fixed-size array values', async () => {
|
||||
const mapKey = 123;
|
||||
const signers = await ethers.getSigners();
|
||||
|
||||
const expectedValue = signers.slice(0, 3)
|
||||
.map(signer => signer.address.toLowerCase());
|
||||
|
||||
await testMappingTypes.setUintFixedArrayMap(mapKey, expectedValue);
|
||||
const blockHash = await getBlockHash();
|
||||
const { value, proof } = await getStorageValue(storageLayout, getStorageAt, blockHash, testMappingTypes.address, 'uintFixedArrayMap', mapKey);
|
||||
expect(value).to.eql(expectedValue);
|
||||
const proofData = JSON.parse(proof.data);
|
||||
expect(proofData.length).to.equal(expectedValue.length);
|
||||
});
|
||||
|
||||
it('get value for mapping of signed integer keys and dynamically-sized array values', async () => {
|
||||
const mapKey = 123;
|
||||
const expectedValue = [1, 2, 3, 4, 5, 6, 7, 8];
|
||||
|
||||
await testMappingTypes.setIntDynamicArrayMap(mapKey, expectedValue);
|
||||
const blockHash = await getBlockHash();
|
||||
const { value, proof } = await getStorageValue(storageLayout, getStorageAt, blockHash, testMappingTypes.address, 'intDynamicArrayMap', mapKey);
|
||||
expect(value).to.eql(expectedValue.map(BigInt));
|
||||
const proofData = JSON.parse(proof.data);
|
||||
expect(proofData.length).to.equal(expectedValue.length);
|
||||
});
|
||||
|
||||
it('get value for mapping of address keys and dynamic byte array values', async () => {
|
||||
const [signer1] = await ethers.getSigners();
|
||||
const expectedValue = ethers.utils.hexlify(ethers.utils.randomBytes(42));
|
||||
|
||||
await testMappingTypes.setAddressBytesMap(signer1.address, expectedValue);
|
||||
const blockHash = await getBlockHash();
|
||||
const { value } = await getStorageValue(storageLayout, getStorageAt, blockHash, testMappingTypes.address, 'addressBytesMap', signer1.address);
|
||||
expect(value).to.eql(expectedValue);
|
||||
});
|
||||
|
||||
it('get value for mapping of fixed size byte array keys and string type values', async () => {
|
||||
const mapKey = ethers.utils.hexlify(ethers.utils.randomBytes(32));
|
||||
const expectedValue = 'Hello world.';
|
||||
|
||||
await testMappingTypes.setBytesStringMap(mapKey, expectedValue);
|
||||
const blockHash = await getBlockHash();
|
||||
const { value } = await getStorageValue(storageLayout, getStorageAt, blockHash, testMappingTypes.address, 'bytesStringMap', mapKey);
|
||||
expect(value).to.eql(expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('nested mapping type', () => {
|
||||
|
@ -49,6 +49,14 @@ contract TestBasicMapping {
|
||||
// Mapping with address as keys and struct type values.
|
||||
mapping(address => TestStruct) public addressStructMap;
|
||||
|
||||
mapping(uint24 => address[3]) public uintFixedArrayMap;
|
||||
|
||||
mapping(int16 => uint128[]) public intDynamicArrayMap;
|
||||
|
||||
mapping(address => bytes) public addressBytesMap;
|
||||
|
||||
mapping(bytes32 => string) public bytesStringMap;
|
||||
|
||||
// Set variable addressUintMap.
|
||||
function setAddressUintMap(uint value) external {
|
||||
addressUintMap[msg.sender] = value;
|
||||
@ -103,4 +111,24 @@ contract TestBasicMapping {
|
||||
function setAddressStructMap(address key, TestStruct calldata value) external {
|
||||
addressStructMap[key] = value;
|
||||
}
|
||||
|
||||
// Set variable uintFixedArrayMap.
|
||||
function setUintFixedArrayMap(uint24 key, address[3] calldata value) external {
|
||||
uintFixedArrayMap[key] = value;
|
||||
}
|
||||
|
||||
// Set variable intDynamicArrayMap.
|
||||
function setIntDynamicArrayMap(int16 key, uint128[] calldata value) external {
|
||||
intDynamicArrayMap[key] = value;
|
||||
}
|
||||
|
||||
// Set variable addressBytesMap.
|
||||
function setAddressBytesMap(address key, bytes calldata value) external {
|
||||
addressBytesMap[key] = value;
|
||||
}
|
||||
|
||||
// Set variable bytesStringMap.
|
||||
function setBytesStringMap(bytes32 key, string calldata value) external {
|
||||
bytesStringMap[key] = value;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user