|
@@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
import "forge-std/Test.sol";
|
|
import "forge-std/Test.sol";
|
|
|
import "@pythnetwork/entropy-sdk-solidity/EntropyStructs.sol";
|
|
import "@pythnetwork/entropy-sdk-solidity/EntropyStructs.sol";
|
|
|
|
|
+import "@pythnetwork/entropy-sdk-solidity/EntropyStructsV2.sol";
|
|
|
import "@pythnetwork/entropy-sdk-solidity/EntropyEvents.sol";
|
|
import "@pythnetwork/entropy-sdk-solidity/EntropyEvents.sol";
|
|
|
import "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
|
|
import "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
|
|
|
import "@pythnetwork/entropy-sdk-solidity/IEntropy.sol";
|
|
import "@pythnetwork/entropy-sdk-solidity/IEntropy.sol";
|
|
@@ -181,7 +182,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
random.getAccruedPythFees();
|
|
random.getAccruedPythFees();
|
|
|
assertEq(address(random).balance, expectedBalance);
|
|
assertEq(address(random).balance, expectedBalance);
|
|
|
|
|
|
|
|
- EntropyStructs.ProviderInfo memory info1 = random.getProviderInfo(
|
|
|
|
|
|
|
+ EntropyStructsV2.ProviderInfo memory info1 = random.getProviderInfo(
|
|
|
provider1
|
|
provider1
|
|
|
);
|
|
);
|
|
|
assert(
|
|
assert(
|
|
@@ -190,7 +191,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
);
|
|
);
|
|
|
assert(info1.currentCommitmentSequenceNumber < info1.sequenceNumber);
|
|
assert(info1.currentCommitmentSequenceNumber < info1.sequenceNumber);
|
|
|
assert(info1.sequenceNumber <= info1.endSequenceNumber);
|
|
assert(info1.sequenceNumber <= info1.endSequenceNumber);
|
|
|
- EntropyStructs.ProviderInfo memory info2 = random.getProviderInfo(
|
|
|
|
|
|
|
+ EntropyStructsV2.ProviderInfo memory info2 = random.getProviderInfo(
|
|
|
provider2
|
|
provider2
|
|
|
);
|
|
);
|
|
|
assert(
|
|
assert(
|
|
@@ -219,7 +220,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
ALL_ZEROS
|
|
ALL_ZEROS
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- EntropyStructs.Request memory reqAfterReveal = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory reqAfterReveal = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
sequenceNumber
|
|
sequenceNumber
|
|
|
);
|
|
);
|
|
@@ -520,7 +521,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
provider1Uri
|
|
provider1Uri
|
|
|
);
|
|
);
|
|
|
assertInvariants();
|
|
assertInvariants();
|
|
|
- EntropyStructs.ProviderInfo memory info1 = random.getProviderInfo(
|
|
|
|
|
|
|
+ EntropyStructsV2.ProviderInfo memory info1 = random.getProviderInfo(
|
|
|
provider1
|
|
provider1
|
|
|
);
|
|
);
|
|
|
assertEq(info1.endSequenceNumber, newHashChainOffset + 10);
|
|
assertEq(info1.endSequenceNumber, newHashChainOffset + 10);
|
|
@@ -733,7 +734,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function testGetProviderInfo() public {
|
|
function testGetProviderInfo() public {
|
|
|
- EntropyStructs.ProviderInfo memory providerInfo1 = random
|
|
|
|
|
|
|
+ EntropyStructsV2.ProviderInfo memory providerInfo1 = random
|
|
|
.getProviderInfo(provider1);
|
|
.getProviderInfo(provider1);
|
|
|
// These two fields aren't used by the Entropy contract itself -- they're just convenient info to store
|
|
// These two fields aren't used by the Entropy contract itself -- they're just convenient info to store
|
|
|
// on-chain -- so they aren't tested in the other tests.
|
|
// on-chain -- so they aren't tested in the other tests.
|
|
@@ -777,7 +778,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
function testRequestWithCallbackAndReveal() public {
|
|
function testRequestWithCallbackAndReveal() public {
|
|
|
bytes32 userRandomNumber = bytes32(uint(42));
|
|
bytes32 userRandomNumber = bytes32(uint(42));
|
|
|
uint fee = random.getFee(provider1);
|
|
uint fee = random.getFee(provider1);
|
|
|
- EntropyStructs.ProviderInfo memory providerInfo = random
|
|
|
|
|
|
|
+ EntropyStructsV2.ProviderInfo memory providerInfo = random
|
|
|
.getProviderInfo(provider1);
|
|
.getProviderInfo(provider1);
|
|
|
|
|
|
|
|
vm.roll(1234);
|
|
vm.roll(1234);
|
|
@@ -805,8 +806,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
blockNumber: 1234,
|
|
blockNumber: 1234,
|
|
|
requester: user1,
|
|
requester: user1,
|
|
|
useBlockhash: false,
|
|
useBlockhash: false,
|
|
|
- callbackStatus: EntropyStatusConstants.CALLBACK_NOT_STARTED,
|
|
|
|
|
- gasLimit10k: 0
|
|
|
|
|
|
|
+ isRequestWithCallback: true
|
|
|
})
|
|
})
|
|
|
);
|
|
);
|
|
|
vm.roll(1234);
|
|
vm.roll(1234);
|
|
@@ -843,14 +843,14 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
uint64 assignedSequenceNumber = consumer.requestEntropy{value: fee}(
|
|
uint64 assignedSequenceNumber = consumer.requestEntropy{value: fee}(
|
|
|
userRandomNumber
|
|
userRandomNumber
|
|
|
);
|
|
);
|
|
|
- EntropyStructs.Request memory req = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory req = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
|
emit RevealedWithCallback(
|
|
emit RevealedWithCallback(
|
|
|
- req,
|
|
|
|
|
|
|
+ EntropyStructConverter.toV1Request(req),
|
|
|
userRandomNumber,
|
|
userRandomNumber,
|
|
|
provider1Proofs[assignedSequenceNumber],
|
|
provider1Proofs[assignedSequenceNumber],
|
|
|
random.combineRandomValues(
|
|
random.combineRandomValues(
|
|
@@ -880,7 +880,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- EntropyStructs.Request memory reqAfterReveal = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory reqAfterReveal = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
@@ -896,14 +896,14 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
provider1,
|
|
provider1,
|
|
|
userRandomNumber
|
|
userRandomNumber
|
|
|
);
|
|
);
|
|
|
- EntropyStructs.Request memory req = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory req = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
|
emit RevealedWithCallback(
|
|
emit RevealedWithCallback(
|
|
|
- req,
|
|
|
|
|
|
|
+ EntropyStructConverter.toV1Request(req),
|
|
|
userRandomNumber,
|
|
userRandomNumber,
|
|
|
provider1Proofs[assignedSequenceNumber],
|
|
provider1Proofs[assignedSequenceNumber],
|
|
|
random.combineRandomValues(
|
|
random.combineRandomValues(
|
|
@@ -919,7 +919,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
provider1Proofs[assignedSequenceNumber]
|
|
provider1Proofs[assignedSequenceNumber]
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- EntropyStructs.Request memory reqAfterReveal = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory reqAfterReveal = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
@@ -973,7 +973,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
uint64 assignedSequenceNumber = consumer.requestEntropy{value: fee}(
|
|
uint64 assignedSequenceNumber = consumer.requestEntropy{value: fee}(
|
|
|
userRandomNumber
|
|
userRandomNumber
|
|
|
);
|
|
);
|
|
|
- EntropyStructs.Request memory req = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory req = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
@@ -983,7 +983,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
|
|
|
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
|
emit RevealedWithCallback(
|
|
emit RevealedWithCallback(
|
|
|
- req,
|
|
|
|
|
|
|
+ EntropyStructConverter.toV1Request(req),
|
|
|
userRandomNumber,
|
|
userRandomNumber,
|
|
|
provider1Proofs[assignedSequenceNumber],
|
|
provider1Proofs[assignedSequenceNumber],
|
|
|
random.combineRandomValues(
|
|
random.combineRandomValues(
|
|
@@ -1010,7 +1010,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- EntropyStructs.Request memory reqAfterReveal = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory reqAfterReveal = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
@@ -1058,7 +1058,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Verify request is still active after failure
|
|
// Verify request is still active after failure
|
|
|
- EntropyStructs.Request memory reqAfterFailure = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory reqAfterFailure = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
@@ -1089,7 +1089,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
consumer.setReverts(false);
|
|
consumer.setReverts(false);
|
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
|
emit RevealedWithCallback(
|
|
emit RevealedWithCallback(
|
|
|
- reqAfterFailure,
|
|
|
|
|
|
|
+ EntropyStructConverter.toV1Request(reqAfterFailure),
|
|
|
userRandomNumber,
|
|
userRandomNumber,
|
|
|
provider1Proofs[assignedSequenceNumber],
|
|
provider1Proofs[assignedSequenceNumber],
|
|
|
random.combineRandomValues(
|
|
random.combineRandomValues(
|
|
@@ -1106,7 +1106,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Verify request is cleared after successful reveal
|
|
// Verify request is cleared after successful reveal
|
|
|
- EntropyStructs.Request memory reqAfterReveal = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory reqAfterReveal = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
@@ -1129,7 +1129,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
uint64 assignedSequenceNumber = consumer.requestEntropy{value: fee}(
|
|
uint64 assignedSequenceNumber = consumer.requestEntropy{value: fee}(
|
|
|
userRandomNumber
|
|
userRandomNumber
|
|
|
);
|
|
);
|
|
|
- EntropyStructs.Request memory req = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory req = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
@@ -1172,7 +1172,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Verify request is still active after failure
|
|
// Verify request is still active after failure
|
|
|
- EntropyStructs.Request memory reqAfterFailure = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory reqAfterFailure = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
@@ -1202,7 +1202,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
// Calling without a gas limit should succeed
|
|
// Calling without a gas limit should succeed
|
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
|
emit RevealedWithCallback(
|
|
emit RevealedWithCallback(
|
|
|
- reqAfterFailure,
|
|
|
|
|
|
|
+ EntropyStructConverter.toV1Request(reqAfterFailure),
|
|
|
userRandomNumber,
|
|
userRandomNumber,
|
|
|
provider1Proofs[assignedSequenceNumber],
|
|
provider1Proofs[assignedSequenceNumber],
|
|
|
random.combineRandomValues(
|
|
random.combineRandomValues(
|
|
@@ -1219,7 +1219,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Verify request is cleared after successful reveal
|
|
// Verify request is cleared after successful reveal
|
|
|
- EntropyStructs.Request memory reqAfterReveal = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory reqAfterReveal = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
assignedSequenceNumber
|
|
assignedSequenceNumber
|
|
|
);
|
|
);
|
|
@@ -1283,7 +1283,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
request(user1, provider1, 42, false);
|
|
request(user1, provider1, 42, false);
|
|
|
}
|
|
}
|
|
|
assertInvariants();
|
|
assertInvariants();
|
|
|
- EntropyStructs.ProviderInfo memory info1 = random.getProviderInfo(
|
|
|
|
|
|
|
+ EntropyStructsV2.ProviderInfo memory info1 = random.getProviderInfo(
|
|
|
provider1
|
|
provider1
|
|
|
);
|
|
);
|
|
|
assertEq(info1.currentCommitmentSequenceNumber, 0);
|
|
assertEq(info1.currentCommitmentSequenceNumber, 0);
|
|
@@ -1353,7 +1353,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
seqNumber,
|
|
seqNumber,
|
|
|
provider1Proofs[seqNumber]
|
|
provider1Proofs[seqNumber]
|
|
|
);
|
|
);
|
|
|
- EntropyStructs.ProviderInfo memory info1 = random.getProviderInfo(
|
|
|
|
|
|
|
+ EntropyStructsV2.ProviderInfo memory info1 = random.getProviderInfo(
|
|
|
provider1
|
|
provider1
|
|
|
);
|
|
);
|
|
|
assertEq(info1.sequenceNumber, seqNumber + 1);
|
|
assertEq(info1.sequenceNumber, seqNumber + 1);
|
|
@@ -1374,7 +1374,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
function testSetMaxNumHashes(uint32 maxNumHashes) public {
|
|
function testSetMaxNumHashes(uint32 maxNumHashes) public {
|
|
|
vm.prank(provider1);
|
|
vm.prank(provider1);
|
|
|
random.setMaxNumHashes(maxNumHashes);
|
|
random.setMaxNumHashes(maxNumHashes);
|
|
|
- EntropyStructs.ProviderInfo memory info1 = random.getProviderInfo(
|
|
|
|
|
|
|
+ EntropyStructsV2.ProviderInfo memory info1 = random.getProviderInfo(
|
|
|
provider1
|
|
provider1
|
|
|
);
|
|
);
|
|
|
assertEq(info1.maxNumHashes, maxNumHashes);
|
|
assertEq(info1.maxNumHashes, maxNumHashes);
|
|
@@ -1455,7 +1455,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
emit ProviderDefaultGasLimitUpdated(provider1, 0, newGasLimit);
|
|
emit ProviderDefaultGasLimitUpdated(provider1, 0, newGasLimit);
|
|
|
random.setDefaultGasLimit(newGasLimit);
|
|
random.setDefaultGasLimit(newGasLimit);
|
|
|
|
|
|
|
|
- EntropyStructs.ProviderInfo memory info = random.getProviderInfo(
|
|
|
|
|
|
|
+ EntropyStructsV2.ProviderInfo memory info = random.getProviderInfo(
|
|
|
provider1
|
|
provider1
|
|
|
);
|
|
);
|
|
|
assertEq(info.defaultGasLimit, newGasLimit);
|
|
assertEq(info.defaultGasLimit, newGasLimit);
|
|
@@ -1500,7 +1500,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
userRandomNumber
|
|
userRandomNumber
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- EntropyStructs.Request memory req = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory req = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
sequenceNumber
|
|
sequenceNumber
|
|
|
);
|
|
);
|
|
@@ -1601,7 +1601,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Check the gasLimit10k field in the request
|
|
// Check the gasLimit10k field in the request
|
|
|
- EntropyStructs.Request memory req = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory req = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
sequenceNumber
|
|
sequenceNumber
|
|
|
);
|
|
);
|
|
@@ -1649,7 +1649,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
|
|
|
|
|
consumer.setTargetGasUsage(callbackGasUsage);
|
|
consumer.setTargetGasUsage(callbackGasUsage);
|
|
|
|
|
|
|
|
- EntropyStructs.Request memory req = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory req = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
sequenceNumber
|
|
sequenceNumber
|
|
|
);
|
|
);
|
|
@@ -1678,7 +1678,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Verify request is still active after failure
|
|
// Verify request is still active after failure
|
|
|
- EntropyStructs.Request memory reqAfterFailure = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory reqAfterFailure = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
sequenceNumber
|
|
sequenceNumber
|
|
|
);
|
|
);
|
|
@@ -1690,7 +1690,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
} else {
|
|
} else {
|
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
vm.expectEmit(false, false, false, true, address(random));
|
|
|
emit RevealedWithCallback(
|
|
emit RevealedWithCallback(
|
|
|
- req,
|
|
|
|
|
|
|
+ EntropyStructConverter.toV1Request(req),
|
|
|
userRandomNumber,
|
|
userRandomNumber,
|
|
|
provider1Proofs[sequenceNumber],
|
|
provider1Proofs[sequenceNumber],
|
|
|
random.combineRandomValues(
|
|
random.combineRandomValues(
|
|
@@ -1707,7 +1707,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Verify request is cleared after successful callback
|
|
// Verify request is cleared after successful callback
|
|
|
- EntropyStructs.Request memory reqAfterSuccess = random.getRequest(
|
|
|
|
|
|
|
+ EntropyStructsV2.Request memory reqAfterSuccess = random.getRequest(
|
|
|
provider1,
|
|
provider1,
|
|
|
sequenceNumber
|
|
sequenceNumber
|
|
|
);
|
|
);
|