mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adding semantic tests for bytes to bytesNN conversion.
This commit is contained in:
parent
cbb7e53b22
commit
eb457064b1
@ -30,7 +30,6 @@ enum class PanicCode
|
|||||||
DivisionByZero = 0x12, // division or modulo by zero
|
DivisionByZero = 0x12, // division or modulo by zero
|
||||||
EnumConversionError = 0x21, // enum conversion error
|
EnumConversionError = 0x21, // enum conversion error
|
||||||
StorageEncodingError = 0x22, // invalid encoding in storage
|
StorageEncodingError = 0x22, // invalid encoding in storage
|
||||||
FixedBytesConversionError = 0x23, // error converting to fixed bytes type
|
|
||||||
EmptyArrayPop = 0x31, // empty array pop
|
EmptyArrayPop = 0x31, // empty array pop
|
||||||
ArrayOutOfBounds = 0x32, // array out of bounds access
|
ArrayOutOfBounds = 0x32, // array out of bounds access
|
||||||
ResourceError = 0x41, // resource error (too large allocation or too large array)
|
ResourceError = 0x41, // resource error (too large allocation or too large array)
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
contract C {
|
||||||
|
bytes s = "abcdefghabcdefghabcdefghabcdefg";
|
||||||
|
|
||||||
|
function fromMemory(bytes memory m) public returns (bytes16) {
|
||||||
|
assembly { mstore(m, 14) }
|
||||||
|
return bytes16(m);
|
||||||
|
}
|
||||||
|
function fromCalldata(bytes calldata c) external returns (bytes16) {
|
||||||
|
return bytes16(c);
|
||||||
|
}
|
||||||
|
function fromStorage() external returns (bytes32) {
|
||||||
|
return bytes32(s);
|
||||||
|
}
|
||||||
|
function fromSlice(bytes calldata c) external returns (bytes8) {
|
||||||
|
return bytes8(c[0:6]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: true
|
||||||
|
// ----
|
||||||
|
// fromMemory(bytes): 0x20, 16, "abcdefghabcdefgh" -> "abcdefghabcdef\0\0"
|
||||||
|
// fromCalldata(bytes): 0x20, 15, "abcdefghabcdefgh" -> "abcdefghabcdefg\0"
|
||||||
|
// fromStorage() -> "abcdefghabcdefghabcdefghabcdefg\0"
|
||||||
|
// fromSlice(bytes): 0x20, 15, "abcdefghabcdefgh" -> "abcdef\0\0"
|
@ -0,0 +1,28 @@
|
|||||||
|
contract C {
|
||||||
|
bytes s = "abcdefghabcdefgh";
|
||||||
|
bytes sLong = "abcdefghabcdefghabcdefghabcdefgh";
|
||||||
|
|
||||||
|
function fromMemory(bytes memory m) public returns (bytes16) {
|
||||||
|
return bytes16(m);
|
||||||
|
}
|
||||||
|
function fromCalldata(bytes calldata c) external returns (bytes16) {
|
||||||
|
return bytes16(c);
|
||||||
|
}
|
||||||
|
function fromStorage() external returns (bytes16) {
|
||||||
|
return bytes16(s);
|
||||||
|
}
|
||||||
|
function fromStorageLong() external returns (bytes32) {
|
||||||
|
return bytes32(sLong);
|
||||||
|
}
|
||||||
|
function fromSlice(bytes calldata c) external returns (bytes8) {
|
||||||
|
return bytes8(c[1:9]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// fromMemory(bytes): 0x20, 16, "abcdefghabcdefgh" -> "abcdefghabcdefgh"
|
||||||
|
// fromCalldata(bytes): 0x20, 16, "abcdefghabcdefgh" -> "abcdefghabcdefgh"
|
||||||
|
// fromStorage() -> "abcdefghabcdefgh"
|
||||||
|
// fromStorageLong() -> "abcdefghabcdefghabcdefghabcdefgh"
|
||||||
|
// fromSlice(bytes): 0x20, 16, "abcdefghabcdefgh" -> "bcdefgha"
|
@ -0,0 +1,23 @@
|
|||||||
|
contract C {
|
||||||
|
bytes s = "abcdefghabcdefghabcdefghabcdefgha";
|
||||||
|
|
||||||
|
function fromMemory(bytes memory m) public returns (bytes32) {
|
||||||
|
return bytes32(m);
|
||||||
|
}
|
||||||
|
function fromCalldata(bytes calldata c) external returns (bytes32) {
|
||||||
|
return bytes32(c);
|
||||||
|
}
|
||||||
|
function fromStorage() external returns (bytes32) {
|
||||||
|
return bytes32(s);
|
||||||
|
}
|
||||||
|
function fromSlice(bytes calldata c) external returns (bytes32) {
|
||||||
|
return bytes32(c[0:33]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// fromMemory(bytes): 0x20, 33, "abcdefghabcdefghabcdefghabcdefgh", "a" -> "abcdefghabcdefghabcdefghabcdefgh"
|
||||||
|
// fromCalldata(bytes): 0x20, 33, "abcdefghabcdefghabcdefghabcdefgh", "a" -> "abcdefghabcdefghabcdefghabcdefgh"
|
||||||
|
// fromStorage() -> "abcdefghabcdefghabcdefghabcdefgh"
|
||||||
|
// fromSlice(bytes): 0x20, 33, "abcdefghabcdefghabcdefghabcdefgh", "a" -> "abcdefghabcdefghabcdefghabcdefgh"
|
Loading…
Reference in New Issue
Block a user