diff --git a/packages/solidity-mapper/README.md b/packages/solidity-mapper/README.md index 4cfc194e..8c55ce00 100644 --- a/packages/solidity-mapper/README.md +++ b/packages/solidity-mapper/README.md @@ -51,8 +51,8 @@ $ yarn test * [ ] Nested Arrays * [x] Fixed size arrays * [ ] Dynamically-sized arrays - * [ ] Dynamically-sized byte array - * [ ] Bytes + * [x] Dynamically-sized byte array + * [x] Bytes * [x] String * [ ] Structs * [x] Get struct value with all members diff --git a/packages/solidity-mapper/src/storage.test.ts b/packages/solidity-mapper/src/storage.test.ts index c5a64368..d8936c5e 100644 --- a/packages/solidity-mapper/src/storage.test.ts +++ b/packages/solidity-mapper/src/storage.test.ts @@ -270,6 +270,33 @@ describe('Get value from storage', () => { }); }); + describe('dynamically sized byte array', () => { + let testBytes: Contract, storageLayout: StorageLayout; + + before(async () => { + const TestBytes = await ethers.getContractFactory('TestBytes'); + testBytes = await TestBytes.deploy(); + await testBytes.deployed(); + storageLayout = await getStorageLayout('TestBytes'); + }); + + it('get value for byte array length less than 32 bytes', async () => { + const expectedValue = ethers.utils.hexlify(ethers.utils.randomBytes(24)); + await testBytes.setBytesArray(expectedValue); + const blockHash = await getBlockHash(); + const { value } = await getStorageValue(storageLayout, getStorageAt, blockHash, testBytes.address, 'bytesArray'); + expect(value).to.equal(expectedValue); + }); + + it('get value for byte array length more than 32 bytes', async () => { + const expectedValue = ethers.utils.hexlify(ethers.utils.randomBytes(100)); + await testBytes.setBytesArray(expectedValue); + const blockHash = await getBlockHash(); + const { value } = await getStorageValue(storageLayout, getStorageAt, blockHash, testBytes.address, 'bytesArray'); + expect(value).to.equal(expectedValue); + }); + }); + describe('fixed size arrays', () => { let testFixedArrays: Contract, storageLayout: StorageLayout; const int128Array = [100, 200, 300, 400, 500];