more semantic and syntax tests

This commit is contained in:
Saw-mon & Natalie 2023-05-21 17:48:58 +01:00 committed by Anton Bukov
parent 57d7226d1a
commit 283f85b091
5 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,25 @@
library A {
struct S1 {
uint256 x;
}
bytes32 internal constant a = type(S1).typehash;
}
library B {
struct S1 {
uint256 x;
}
bytes32 internal constant b = type(S1).typehash;
}
contract C {
function f() public pure {
assert(A.a == B.b);
}
}
// ====
// SMTEngine: all
// ----
// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

View File

@ -0,0 +1,19 @@
contract A {
struct S {
string x;
}
}
contract B {
struct S {
bool y;
}
}
contract C is A, B {
function f() public pure {
assert(type(A.S).typehash != type(B.S).typehash);
}
}
// ----
// DeclarationError 9097: (72-104): Identifier already declared.

View File

@ -0,0 +1,27 @@
struct S {
uint256 x;
}
bytes32 constant TYPE_HASH_FILE_LEVEL = type(S).typehash;
contract A {
function f() public pure {
// TYPE_HASH_FILE_LEVEL == keccak256("S(uint256 x)")
assert(TYPE_HASH_FILE_LEVEL == 0x2a7af8c10b1d48ad8e0a6aad976d8385e84377b5bd03b59e2c445dc430ac2ca2);
}
}
contract C {
struct S {
uint256 y;
}
function f() public pure {
// type(S).typehash == keccak256("S(uint256 y)") and not the shadowed file-level struct S
assert(type(S).typehash == 0xea24952476a382c98f2d2e42112ff8a673d8ed19d22ffc89ee9fe2f415bf6c35);
assert(type(S).typehash != TYPE_HASH_FILE_LEVEL);
}
}
// ----
// Warning 2519: (327-362): This declaration shadows an existing declaration.
// Info 1391: CHC: 3 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

View File

@ -0,0 +1,15 @@
contract A {
struct S {
string x;
bool[10][] y;
}
}
contract C is A {
function f() public pure {
// keccak256("S(string x,bool[10][] y)")
assert(type(S).typehash == 0xb4abec9b1d4b9d4724891b27b275d7d5e1692fe69fe6ff78379f613500046c11);
}
}
// ----
// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

View File

@ -0,0 +1,11 @@
contract C {
struct S {
uint256[][10][] x;
}
bytes32 immutable h;
constructor() {
h = type(S).typehash;
}
}