|
| 1 | +using A as a; |
| 2 | +using B as b; |
| 3 | +using C as c; |
| 4 | +using D as d; |
| 5 | +using E as ee; |
| 6 | +using F as f; |
| 7 | +using G as g; |
| 8 | +using H as h; |
| 9 | +using I as i; |
| 10 | +using J as j; |
| 11 | + |
| 12 | +// TEST 1: Explicit bool type declaration -> dispatches to A (returns bool) |
| 13 | +rule explicitBoolTypeDispatchesToA(env e) { |
| 14 | + address addr; |
| 15 | + bool result = addr.transfer(e); |
| 16 | + assert addr == a || addr == ee, "Explicit bool LHS should dispatch to contract A"; |
| 17 | + assert addr == a => result == true; |
| 18 | + assert addr == ee => result == false; |
| 19 | +} |
| 20 | + |
| 21 | +// TEST 2: Command form (no LHS) -> should work with A, B, E |
| 22 | +rule commandFormWorksWithVoid(env e) { |
| 23 | + address addr; |
| 24 | + addr.transfer(e); // No return value captured |
| 25 | + assert addr == a || addr == b || addr == ee, "Command form should accept all"; |
| 26 | +} |
| 27 | + |
| 28 | +// TEST 3: Multi-return with two variables -> dispatches to C (uint, uint) |
| 29 | +rule multiReturnTwoVarsDispatchesToC(env e) { |
| 30 | + address addr; |
| 31 | + uint x; |
| 32 | + uint y; |
| 33 | + x, y = addr.multi(e); |
| 34 | + assert addr == c, "Two LHS vars should dispatch to C"; |
| 35 | + assert x == 42 && y == 84; |
| 36 | +} |
| 37 | + |
| 38 | +// TEST 4: Single return -> dispatches to D (uint) |
| 39 | +rule singleReturnDispatchesToD(env e) { |
| 40 | + address addr; |
| 41 | + uint result = addr.multi(e); |
| 42 | + assert addr == d, "Single LHS var should dispatch to D"; |
| 43 | + assert result == 100; |
| 44 | +} |
| 45 | + |
| 46 | +// TEST 5: Assignment without type declaration (variable pre-declared) |
| 47 | +rule assignmentToPreDeclaredBoolVar(env e) { |
| 48 | + address addr; |
| 49 | + bool existingVar; |
| 50 | + existingVar = addr.transfer(e); // No type on this line, but existingVar is bool |
| 51 | + assert addr == a || addr == ee, "Pre-declared bool var should provide type hint"; |
| 52 | +} |
| 53 | + |
| 54 | +// TEST 6: Assignment without type declaration for uint |
| 55 | +rule assignmentToPreDeclaredUintVar(env e) { |
| 56 | + address addr; |
| 57 | + uint existingVar; |
| 58 | + existingVar = addr.multi(e); // No type on this line |
| 59 | + assert addr == d, "Pre-declared uint var should dispatch to D"; |
| 60 | +} |
| 61 | + |
| 62 | +// TEST 7: Multiple contracts with same return type - both are valid targets |
| 63 | +rule multipleMatchingContractsBool(env e) { |
| 64 | + address addr; |
| 65 | + bool result = addr.transfer(e); |
| 66 | + // Both A and E return bool |
| 67 | + assert addr == a || addr == ee, "Both A and E should be valid for bool return"; |
| 68 | +} |
| 69 | + |
| 70 | +// TEST 8: Subtype - uint8 result assigned to uint256 variable |
| 71 | +rule subtypeUint8ToUint256(env e) { |
| 72 | + address addr; |
| 73 | + uint256 result = addr.getValue(e); |
| 74 | + // G returns uint256 (exact match), F returns uint8 (convertible?) |
| 75 | + assert addr == g || addr == f, "Check subtype compatibility"; |
| 76 | +} |
| 77 | + |
| 78 | +// TEST 9: Tuple order (uint, bool) -> dispatches to H |
| 79 | +rule tupleOrderUintBool(env e) { |
| 80 | + address addr; |
| 81 | + uint x; |
| 82 | + bool y; |
| 83 | + x, y = addr.getPair(e); |
| 84 | + assert addr == h, "(uint, bool) order should dispatch to H"; |
| 85 | + assert x == 1 && y == true; |
| 86 | +} |
| 87 | + |
| 88 | +// TEST 10: Tuple order (bool, uint) -> dispatches to I |
| 89 | +rule tupleOrderBoolUint(env e) { |
| 90 | + address addr; |
| 91 | + bool x; |
| 92 | + uint y; |
| 93 | + x, y = addr.getPair(e); |
| 94 | + assert addr == i, "(bool, uint) order should dispatch to I"; |
| 95 | + assert x == true && y == 2; |
| 96 | +} |
| 97 | + |
| 98 | +// TEST 11: Triple return value |
| 99 | +rule tripleReturnValues(env e) { |
| 100 | + address addr; |
| 101 | + uint x; |
| 102 | + uint y; |
| 103 | + uint z; |
| 104 | + x, y, z = addr.getTriple(e); |
| 105 | + assert addr == j, "Triple return should dispatch to J"; |
| 106 | + assert x == 1 && y == 2 && z == 3; |
| 107 | +} |
| 108 | + |
| 109 | +// TEST 12: Wildcard with one variable - x, _ = addr.multi(e) |
| 110 | +rule wildcardWithOneVar(env e) { |
| 111 | + address addr; |
| 112 | + uint x; |
| 113 | + x, _ = addr.multi(e); |
| 114 | + assert addr == c, "One var + wildcard should dispatch to C (uint, uint)"; |
| 115 | + assert x == 42; |
| 116 | +} |
| 117 | + |
| 118 | +// TEST 13: Double wildcard - _, _ = addr.multi(e) |
| 119 | +rule doubleWildcard(env e) { |
| 120 | + address addr; |
| 121 | + _, _ = addr.multi(e); |
| 122 | + assert addr == c, "Double wildcard with 2 positions should dispatch to C"; |
| 123 | +} |
0 commit comments