Skip to content

Commit 2fc334e

Browse files
committed
minor tweaks
1 parent 6e06df1 commit 2fc334e

File tree

3 files changed

+115
-38
lines changed

3 files changed

+115
-38
lines changed

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

Lines changed: 102 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,8 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
17351735
gasLimit
17361736
);
17371737

1738-
EntropyStructsV2.ProviderInfo memory providerInfo = random.getProviderInfoV2(provider1);
1738+
EntropyStructsV2.ProviderInfo memory providerInfo = random
1739+
.getProviderInfoV2(provider1);
17391740

17401741
uint128 startingAccruedProviderFee = providerInfo.accruedFeesInWei;
17411742
vm.expectEmit(false, false, false, true, address(random));
@@ -1746,7 +1747,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
17461747
userRandomNumber,
17471748
uint32(expectedGasLimit10k) * 10000,
17481749
bytes("")
1749-
);
1750+
);
17501751
vm.prank(user1);
17511752
uint64 sequenceNumber = random.requestWithCallbackAndGasLimit{
17521753
value: fee
@@ -1813,7 +1814,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
18131814
);
18141815

18151816
if (!expectSuccess) {
1816-
vm.recordLogs();
1817+
vm.recordLogs();
18171818
random.revealWithCallback(
18181819
provider1,
18191820
sequenceNumber,
@@ -1823,28 +1824,59 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
18231824
Vm.Log[] memory entries = vm.getRecordedLogs();
18241825

18251826
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)"));
1827+
// first entry is CallbackFailed which we aren't going to check.
1828+
// Unfortunately event.selector was added in Solidity 0.8.15 and we're on 0.8.4 so we have to copy this spec here.
1829+
assertEq(
1830+
entries[1].topics[0],
1831+
keccak256(
1832+
"Revealed(address,address,uint64,bytes32,bool,bytes,uint32,bytes)"
1833+
)
1834+
);
18281835
// 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)))));
1836+
assertEq(
1837+
entries[1].topics[1],
1838+
bytes32(uint256(uint160(provider1)))
1839+
);
1840+
assertEq(
1841+
entries[1].topics[2],
1842+
bytes32(uint256(uint160(address(consumer))))
1843+
);
18311844
assertEq(entries[1].topics[3], bytes32(uint256(sequenceNumber)));
1832-
1845+
18331846
// Verify the data field contains the expected values (per event ABI)
1834-
(bytes32 randomNumber, bool callbackFailed, bytes memory callbackErrorCode, uint32 callbackGasUsed, bytes memory _dummy) =
1835-
abi.decode(entries[1].data, (bytes32, bool, bytes, uint32, bytes));
1836-
1837-
assertEq(randomNumber, random.combineRandomValues(
1838-
userRandomNumber,
1839-
provider1Proofs[sequenceNumber],
1840-
0
1841-
));
1847+
(
1848+
bytes32 randomNumber,
1849+
bool callbackFailed,
1850+
bytes memory callbackErrorCode,
1851+
uint32 callbackGasUsed,
1852+
bytes memory extraArgs
1853+
) = abi.decode(
1854+
entries[1].data,
1855+
(bytes32, bool, bytes, uint32, bytes)
1856+
);
1857+
1858+
assertEq(
1859+
randomNumber,
1860+
random.combineRandomValues(
1861+
userRandomNumber,
1862+
provider1Proofs[sequenceNumber],
1863+
0
1864+
)
1865+
);
18421866
assertEq(callbackFailed, true);
18431867
assertEq(callbackErrorCode, bytes(""));
18441868

1845-
// callback gas usage is approximate and only triggered when the provider has set a gas limit
1846-
assertTrue(random.getProviderInfoV2(provider1).defaultGasLimit == 0 || ((callbackGasUsage * 98) / 100 < callbackGasUsed));
1847-
assertTrue(random.getProviderInfoV2(provider1).defaultGasLimit == 0 || (callbackGasUsed < (callbackGasUsage * 102) / 100));
1869+
// callback gas usage is approximate and only triggered when the provider has set a gas limit.
1870+
// Note: this condition is somewhat janky, but we hit the stack limit so can't put in any more local variables :(
1871+
assertTrue(
1872+
random.getProviderInfoV2(provider1).defaultGasLimit == 0 ||
1873+
((callbackGasUsage * 98) / 100 < callbackGasUsed)
1874+
);
1875+
assertTrue(
1876+
random.getProviderInfoV2(provider1).defaultGasLimit == 0 ||
1877+
(callbackGasUsed < (callbackGasUsage * 102) / 100)
1878+
);
1879+
assertEq(extraArgs, bytes(""));
18481880

18491881
// Verify request is still active after failure
18501882
EntropyStructsV2.Request memory reqAfterFailure = random
@@ -1866,29 +1898,62 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
18661898
Vm.Log[] memory entries = vm.getRecordedLogs();
18671899

18681900
assertEq(entries.length, 2);
1869-
assertEq(entries[1].topics[0], keccak256("Revealed(address,address,uint64,bytes32,bool,bytes,uint32,bytes)"));
1870-
1901+
// first entry is CallbackFailed which we aren't going to check.
1902+
// Unfortunately event.selector was added in Solidity 0.8.15 and we're on 0.8.4 so we have to copy this spec here.
1903+
assertEq(
1904+
entries[1].topics[0],
1905+
keccak256(
1906+
"Revealed(address,address,uint64,bytes32,bool,bytes,uint32,bytes)"
1907+
)
1908+
);
1909+
18711910
// Verify the topics match the expected values
1872-
assertEq(entries[1].topics[1], bytes32(uint256(uint160(provider1))));
1873-
assertEq(entries[1].topics[2], bytes32(uint256(uint160(req.requester))));
1874-
assertEq(entries[1].topics[3], bytes32(uint256(req.sequenceNumber)));
1875-
1911+
assertEq(
1912+
entries[1].topics[1],
1913+
bytes32(uint256(uint160(provider1)))
1914+
);
1915+
assertEq(
1916+
entries[1].topics[2],
1917+
bytes32(uint256(uint160(req.requester)))
1918+
);
1919+
assertEq(
1920+
entries[1].topics[3],
1921+
bytes32(uint256(req.sequenceNumber))
1922+
);
1923+
18761924
// Verify the data field contains the expected values (per event ABI)
1877-
(bytes32 randomNumber, bool callbackFailed, bytes memory callbackErrorCode, uint32 callbackGasUsed, bytes memory _dummy) =
1878-
abi.decode(entries[1].data, (bytes32, bool, bytes, uint32, bytes));
1879-
1880-
assertEq(randomNumber, random.combineRandomValues(
1881-
userRandomNumber,
1882-
provider1Proofs[sequenceNumber],
1883-
0
1884-
));
1925+
(
1926+
bytes32 randomNumber,
1927+
bool callbackFailed,
1928+
bytes memory callbackErrorCode,
1929+
uint32 callbackGasUsed,
1930+
bytes memory extraArgs
1931+
) = abi.decode(
1932+
entries[1].data,
1933+
(bytes32, bool, bytes, uint32, bytes)
1934+
);
1935+
1936+
assertEq(
1937+
randomNumber,
1938+
random.combineRandomValues(
1939+
userRandomNumber,
1940+
provider1Proofs[sequenceNumber],
1941+
0
1942+
)
1943+
);
18851944
assertEq(callbackFailed, false);
18861945
assertEq(callbackErrorCode, bytes(""));
1887-
console.log(callbackGasUsage);
1888-
console.log(callbackGasUsed);
18891946
// callback gas usage is approximate and only triggered when the provider has set a gas limit
1890-
assertTrue(random.getProviderInfoV2(provider1).defaultGasLimit == 0 || ((callbackGasUsage * 90) / 100 < callbackGasUsed));
1891-
assertTrue(random.getProviderInfoV2(provider1).defaultGasLimit == 0 || (callbackGasUsed < (callbackGasUsage * 110) / 100));
1947+
// Note: this condition is somewhat janky, but we hit the stack limit so can't put in any more local variables :(
1948+
assertTrue(
1949+
random.getProviderInfoV2(provider1).defaultGasLimit == 0 ||
1950+
((callbackGasUsage * 90) / 100 < callbackGasUsed)
1951+
);
1952+
assertTrue(
1953+
random.getProviderInfoV2(provider1).defaultGasLimit == 0 ||
1954+
(callbackGasUsed < (callbackGasUsage * 110) / 100)
1955+
);
1956+
assertEq(extraArgs, bytes(""));
18921957

18931958
// Verify request is cleared after successful callback
18941959
EntropyStructsV2.Request memory reqAfterSuccess = random

target_chains/ethereum/entropy_sdk/solidity/EntropyEventsV2.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ interface EntropyEventsV2 {
5656
bytes32 randomNumber,
5757
bool callbackFailed,
5858
bytes callbackReturnValue,
59-
uint32 callbackGasUsed,
59+
uint32 callbackGasUsed,
6060
bytes extraArgs
6161
);
6262

target_chains/ethereum/entropy_sdk/solidity/abis/IEntropy.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,12 @@
504504
"name": "userRandomNumber",
505505
"type": "bytes32"
506506
},
507+
{
508+
"indexed": false,
509+
"internalType": "uint32",
510+
"name": "gasLimit",
511+
"type": "uint32"
512+
},
507513
{
508514
"indexed": false,
509515
"internalType": "bytes",
@@ -711,6 +717,12 @@
711717
"name": "callbackReturnValue",
712718
"type": "bytes"
713719
},
720+
{
721+
"indexed": false,
722+
"internalType": "uint32",
723+
"name": "callbackGasUsed",
724+
"type": "uint32"
725+
},
714726
{
715727
"indexed": false,
716728
"internalType": "bytes",

0 commit comments

Comments
 (0)