Tests for dynamically sized byte arrays.

This commit is contained in:
nikugogoi 2021-06-16 15:29:04 +05:30 committed by Ashwin Phatak
parent b505332970
commit 7c4fef153e
2 changed files with 29 additions and 2 deletions

View File

@ -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

View File

@ -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];