Skip to content

Commit 3a42a0e

Browse files
committed
new log testing
1 parent c743548 commit 3a42a0e

File tree

3 files changed

+53
-39
lines changed

3 files changed

+53
-39
lines changed

target_chains/ethereum/contracts/contracts/entropy/Entropy.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ abstract contract Entropy is IEntropy, EntropyState {
600600
randomNumber,
601601
false,
602602
ret,
603+
SafeCast.toUint32(startingGas - gasleft()),
603604
bytes("")
604605
);
605606
clearRequest(provider, sequenceNumber);
@@ -629,6 +630,7 @@ abstract contract Entropy is IEntropy, EntropyState {
629630
randomNumber,
630631
true,
631632
ret,
633+
SafeCast.toUint32(startingGas - gasleft()),
632634
bytes("")
633635
);
634636
req.callbackStatus = EntropyStatusConstants.CALLBACK_FAILED;
@@ -656,6 +658,7 @@ abstract contract Entropy is IEntropy, EntropyState {
656658
randomNumber,
657659
false,
658660
bytes(""),
661+
0, // gas usage not tracked in the old no-gas-limit flow.
659662
bytes("")
660663
);
661664

target_chains/ethereum/contracts/forge-test/Entropy.t.sol

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
878878
0
879879
)
880880
);
881-
vm.expectEmit(false, false, false, true, address(random));
881+
vm.expectEmit(true, true, true, false, address(random));
882882
emit EntropyEventsV2.Revealed(
883883
provider1,
884884
req.requester,
@@ -890,6 +890,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
890890
),
891891
false,
892892
bytes(""),
893+
0,
893894
bytes("")
894895
);
895896
vm.prank(user1);
@@ -945,7 +946,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
945946
0
946947
)
947948
);
948-
vm.expectEmit(false, false, false, true, address(random));
949+
vm.expectEmit(true, true, true, false, address(random));
949950
emit EntropyEventsV2.Revealed(
950951
provider1,
951952
req.requester,
@@ -957,6 +958,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
957958
),
958959
false,
959960
bytes(""),
961+
0,
960962
bytes("")
961963
);
962964
random.revealWithCallback(
@@ -1051,7 +1053,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
10511053
0
10521054
)
10531055
);
1054-
vm.expectEmit(false, false, false, true, address(random));
1056+
vm.expectEmit(true, true, true, false, address(random));
10551057
emit EntropyEventsV2.Revealed(
10561058
provider1,
10571059
req.requester,
@@ -1063,6 +1065,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
10631065
),
10641066
false,
10651067
bytes(""),
1068+
0,
10661069
bytes("")
10671070
);
10681071
random.revealWithCallback(
@@ -1123,7 +1126,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
11231126
),
11241127
revertReason
11251128
);
1126-
vm.expectEmit(false, false, false, true, address(random));
1129+
vm.expectEmit(true, true, true, false, address(random));
11271130
emit EntropyEventsV2.Revealed(
11281131
provider1,
11291132
address(consumer),
@@ -1135,6 +1138,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
11351138
),
11361139
true,
11371140
revertReason,
1141+
0,
11381142
bytes("")
11391143
);
11401144
random.revealWithCallback(
@@ -1188,7 +1192,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
11881192
0
11891193
)
11901194
);
1191-
vm.expectEmit(false, false, false, true, address(random));
1195+
vm.expectEmit(true, true, true, false, address(random));
11921196
emit EntropyEventsV2.Revealed(
11931197
provider1,
11941198
reqAfterFailure.requester,
@@ -1200,6 +1204,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
12001204
),
12011205
false,
12021206
bytes(""),
1207+
0,
12031208
bytes("")
12041209
);
12051210
random.revealWithCallback(
@@ -1268,7 +1273,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
12681273
// out-of-gas reverts have an empty bytes array as the return value.
12691274
""
12701275
);
1271-
vm.expectEmit(false, false, false, true, address(random));
1276+
vm.expectEmit(true, true, true, false, address(random));
12721277
emit EntropyEventsV2.Revealed(
12731278
provider1,
12741279
address(consumer),
@@ -1280,7 +1285,8 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
12801285
),
12811286
true,
12821287
"",
1283-
""
1288+
0,
1289+
bytes("")
12841290
);
12851291
random.revealWithCallback(
12861292
provider1,
@@ -1332,7 +1338,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
13321338
0
13331339
)
13341340
);
1335-
vm.expectEmit(false, false, false, true, address(random));
1341+
vm.expectEmit(true, true, true, false, address(random));
13361342
emit EntropyEventsV2.Revealed(
13371343
provider1,
13381344
address(consumer),
@@ -1344,7 +1350,8 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
13441350
),
13451351
false,
13461352
"",
1347-
""
1353+
0,
1354+
bytes("")
13481355
);
13491356
random.revealWithCallback(
13501357
provider1,
@@ -1806,41 +1813,42 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
18061813
);
18071814

18081815
if (!expectSuccess) {
1809-
vm.expectEmit(false, false, false, true, address(random));
1810-
emit CallbackFailed(
1811-
provider1,
1812-
address(consumer),
1813-
sequenceNumber,
1814-
userRandomNumber,
1815-
provider1Proofs[sequenceNumber],
1816-
random.combineRandomValues(
1817-
userRandomNumber,
1818-
provider1Proofs[sequenceNumber],
1819-
0
1820-
),
1821-
// out-of-gas reverts have an empty bytes array as the return value.
1822-
""
1823-
);
1824-
vm.expectEmit(false, false, false, true, address(random));
1825-
emit EntropyEventsV2.Revealed(
1826-
provider1,
1827-
address(consumer),
1828-
sequenceNumber,
1829-
random.combineRandomValues(
1830-
userRandomNumber,
1831-
provider1Proofs[sequenceNumber],
1832-
0
1833-
),
1834-
true,
1835-
bytes(""),
1836-
bytes("")
1837-
);
1816+
vm.recordLogs();
18381817
random.revealWithCallback(
18391818
provider1,
18401819
sequenceNumber,
18411820
userRandomNumber,
18421821
provider1Proofs[sequenceNumber]
18431822
);
1823+
Vm.Log[] memory entries = vm.getRecordedLogs();
1824+
1825+
assertEq(entries.length, 2);
1826+
// first entry is CallbackFailed
1827+
assertEq(entries[1].topics[0], keccak256("Revealed(address,address,uint64,bytes32,bool,bytes,uint32,bytes)"));
1828+
// Verify the topics match the expected values
1829+
assertEq(entries[1].topics[1], bytes32(uint256(uint160(provider1))));
1830+
assertEq(entries[1].topics[2], bytes32(uint256(uint160(address(consumer)))));
1831+
assertEq(entries[1].topics[3], bytes32(uint256(sequenceNumber)));
1832+
1833+
// Verify the data field contains the expected values
1834+
// The data field contains the non-indexed parameters in order:
1835+
// randomNumber, callbackFailed, callbackErrorCode, callbackGasUsed, dummy
1836+
bytes32 expectedRandomNumber = random.combineRandomValues(
1837+
userRandomNumber,
1838+
provider1Proofs[sequenceNumber],
1839+
0
1840+
);
1841+
1842+
// Decode the data field
1843+
(bytes32 randomNumber, bool callbackFailed, bytes memory callbackErrorCode, uint32 callbackGasUsed, bytes memory dummy) =
1844+
abi.decode(entries[1].data, (bytes32, bool, bytes, uint32, bytes));
1845+
1846+
// Verify each field matches the expected values
1847+
assertEq(randomNumber, expectedRandomNumber);
1848+
assertEq(callbackFailed, true);
1849+
assertEq(callbackErrorCode, bytes(""));
1850+
// assertEq(callbackGasUsed, 0);
1851+
assertEq(dummy, bytes(""));
18441852

18451853
// Verify request is still active after failure
18461854
EntropyStructsV2.Request memory reqAfterFailure = random
@@ -1862,7 +1870,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
18621870
0
18631871
)
18641872
);
1865-
vm.expectEmit(false, false, false, true, address(random));
1873+
vm.expectEmit(true, true, true, false, address(random));
18661874
emit EntropyEventsV2.Revealed(
18671875
provider1,
18681876
req.requester,
@@ -1874,6 +1882,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
18741882
),
18751883
false,
18761884
bytes(""),
1885+
0,
18771886
bytes("")
18781887
);
18791888
random.revealWithCallback(

target_chains/ethereum/entropy_sdk/solidity/EntropyEventsV2.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ interface EntropyEventsV2 {
4646
* @param callbackReturnValue Return value from the callback. If the callback failed, this field contains
4747
* the error code and any additional returned data. Note that "" often indicates an out-of-gas error.
4848
* If the callback returns more than 256 bytes, only the first 256 bytes of the callback return value are included.
49+
* @param callbackGasUsed How much gas the callback used.
4950
* @param extraArgs A field for extra data for forward compatibility.
5051
*/
5152
event Revealed(
@@ -55,6 +56,7 @@ interface EntropyEventsV2 {
5556
bytes32 randomNumber,
5657
bool callbackFailed,
5758
bytes callbackReturnValue,
59+
uint32 callbackGasUsed,
5860
bytes extraArgs
5961
);
6062

0 commit comments

Comments
 (0)