watcher-ts/packages/solidity-mapper/test/contracts/TestBytes.sol
Ashwin Phatak b243025ca8
Test cases in solidity-mapper for contract, fixed-size byte arrays and enum types (#26)
* Add tests for getStorageInfo and getEventNameTopics.

* Lint solidity-mapper package code.

* Add test for contract type.

* Add test for fixed size byte arrays.

* Add test for Enum types.

* Add tests for variables packed together and using single slot.

* Fix comments in test contracts.

Co-authored-by: nikugogoi <95nikass@gmail.com>
2021-06-02 11:23:33 +05:30

38 lines
1.2 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract TestBytes {
// Byte array variables are packed together in a slot as they occupy less than 32 bytes together.
bytes10 bytesTen;
bytes20 bytesTwenty;
// Byte array variable is stored in the next slot as there is not enough space for it in the previous slot.
bytes30 bytesThirty;
// Dynamically sized byte arrays will take the next single slot.
// If data is 32 or more bytes, the main slot stores the value length * 2 + 1 and the data is stored in keccak256(slot).
// Else the main slot stores the data and value length * 2.
// https://docs.soliditylang.org/en/v0.7.4/internals/layout_in_storage.html#bytes-and-string
bytes bytesArray;
// Set variable bytesTen.
function setBytesTen(bytes10 value) external {
bytesTen = value;
}
// Set variable bytesTwenty.
function setBytesTwenty(bytes20 value) external {
bytesTwenty = value;
}
// Set variable bytesThirty.
function setBytesThirty(bytes30 value) external {
bytesThirty = value;
}
// Set variable bytesArray.
function setBytesArray(bytes calldata value) external {
bytesArray = value;
}
}