From 254eca08c69c98d454234aa0bed57a970d1bd523 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Mon, 27 Nov 2023 10:20:12 -0800 Subject: [PATCH] test new abi --- .../contracts/contracts/entropy/Entropy.sol | 12 ++--- .../contracts/forge-test/Entropy.t.sol | 49 ++++++++++++++++--- .../entropy_sdk/solidity/EntropyStructs.sol | 4 ++ .../entropy_sdk/solidity/IEntropy.sol | 3 +- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/target_chains/ethereum/contracts/contracts/entropy/Entropy.sol b/target_chains/ethereum/contracts/contracts/entropy/Entropy.sol index 746a01678..37d886d25 100644 --- a/target_chains/ethereum/contracts/contracts/entropy/Entropy.sol +++ b/target_chains/ethereum/contracts/contracts/entropy/Entropy.sol @@ -72,14 +72,6 @@ import "./EntropyState.sol"; // protocol prior to the random number being revealed (i.e., prior to step (6) above). Integrators should ensure that // the user is always incentivized to reveal their random number, and that the protocol has an escape hatch for // cases where the user chooses not to reveal. -// -// TODOs: -// - governance?? -// - correct method access modifiers (public vs external) -// - gas optimizations -// - function to check invariants?? -// - need to increment pyth fees if someone transfers funds to the contract via another method -// - off-chain data ERC support? contract Entropy is IEntropy, EntropyState { // TODO: Use an upgradeable proxy constructor(uint pythFeeInWei, address defaultProvider) { @@ -97,7 +89,8 @@ contract Entropy is IEntropy, EntropyState { uint feeInWei, bytes32 commitment, bytes calldata commitmentMetadata, - uint64 chainLength + uint64 chainLength, + bytes calldata uri ) public override { if (chainLength == 0) revert EntropyErrors.AssertionFailure(); @@ -118,6 +111,7 @@ contract Entropy is IEntropy, EntropyState { provider.currentCommitmentSequenceNumber = provider.sequenceNumber; provider.commitmentMetadata = commitmentMetadata; provider.endSequenceNumber = provider.sequenceNumber + chainLength; + provider.uri = uri; provider.sequenceNumber += 1; diff --git a/target_chains/ethereum/contracts/forge-test/Entropy.t.sol b/target_chains/ethereum/contracts/forge-test/Entropy.t.sol index 700bc738a..0ec5910a9 100644 --- a/target_chains/ethereum/contracts/forge-test/Entropy.t.sol +++ b/target_chains/ethereum/contracts/forge-test/Entropy.t.sol @@ -19,10 +19,13 @@ contract EntropyTest is Test { bytes32[] provider1Proofs; uint provider1FeeInWei = 8; uint64 provider1ChainLength = 100; + bytes provider1Uri = bytes("https://foo.com"); + bytes provider1CommitmentMetadata = hex"0100"; address public provider2 = address(2); bytes32[] provider2Proofs; uint provider2FeeInWei = 20; + bytes provider2Uri = bytes("https://bar.com"); address public user1 = address(3); address public user2 = address(4); @@ -44,14 +47,21 @@ contract EntropyTest is Test { random.register( provider1FeeInWei, provider1Proofs[0], - hex"0100", - provider1ChainLength + provider1CommitmentMetadata, + provider1ChainLength, + provider1Uri ); bytes32[] memory hashChain2 = generateHashChain(provider2, 0, 100); provider2Proofs = hashChain2; vm.prank(provider2); - random.register(provider2FeeInWei, provider2Proofs[0], hex"0200", 100); + random.register( + provider2FeeInWei, + provider2Proofs[0], + hex"0200", + 100, + provider2Uri + ); } function generateHashChain( @@ -346,7 +356,13 @@ contract EntropyTest is Test { 10 ); vm.prank(provider1); - random.register(provider1FeeInWei, newHashChain[0], hex"0100", 10); + random.register( + provider1FeeInWei, + newHashChain[0], + hex"0100", + 10, + provider1Uri + ); assertInvariants(); EntropyStructs.ProviderInfo memory info1 = random.getProviderInfo( provider1 @@ -415,7 +431,13 @@ contract EntropyTest is Test { // Check that overflowing the fee arithmetic causes the transaction to revert. vm.prank(provider1); - random.register(MAX_UINT256, provider1Proofs[0], hex"0100", 100); + random.register( + MAX_UINT256, + provider1Proofs[0], + hex"0100", + 100, + provider1Uri + ); vm.expectRevert(); random.getFee(provider1); } @@ -465,7 +487,13 @@ contract EntropyTest is Test { // Reregistering updates the required fees vm.prank(provider1); - random.register(12345, provider1Proofs[0], hex"0100", 100); + random.register( + 12345, + provider1Proofs[0], + hex"0100", + 100, + provider1Uri + ); assertRequestReverts(pythFeeInWei + 12345 - 1, provider1, 42, false); requestWithFee(user2, pythFeeInWei + 12345, provider1, 42, false); @@ -494,4 +522,13 @@ contract EntropyTest is Test { vm.expectRevert(); random.withdraw(providerOneBalance); } + + function testGetProviderInfo() public { + EntropyStructs.ProviderInfo memory providerInfo1 = random + .getProviderInfo(provider1); + // 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. + assertEq(providerInfo1.uri, provider1Uri); + assertEq(providerInfo1.commitmentMetadata, provider1CommitmentMetadata); + } } diff --git a/target_chains/ethereum/entropy_sdk/solidity/EntropyStructs.sol b/target_chains/ethereum/entropy_sdk/solidity/EntropyStructs.sol index 24bf575c3..dc011f926 100644 --- a/target_chains/ethereum/entropy_sdk/solidity/EntropyStructs.sol +++ b/target_chains/ethereum/entropy_sdk/solidity/EntropyStructs.sol @@ -21,6 +21,10 @@ contract EntropyStructs { // Metadata for the current commitment. Providers may optionally use this field to to help // manage rotations (i.e., to pick the sequence number from the correct hash chain). bytes commitmentMetadata; + // Optional URI where clients can retrieve revelations for the provider. + // Client SDKs can use this field to automatically determine how to retrieve random values for each provider. + // TODO: specify the API that must be implemented at this URI + bytes uri; // The first sequence number that is *not* included in the current commitment (i.e., an exclusive end index). // The contract maintains the invariant that sequenceNumber <= endSequenceNumber. // If sequenceNumber == endSequenceNumber, the provider must rotate their commitment to add additional random values. diff --git a/target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol b/target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol index ab354180b..965b2cce1 100644 --- a/target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol +++ b/target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol @@ -13,7 +13,8 @@ interface IEntropy is EntropyEvents { uint feeInWei, bytes32 commitment, bytes calldata commitmentMetadata, - uint64 chainLength + uint64 chainLength, + bytes calldata uri ) external; // Withdraw a portion of the accumulated fees for the provider msg.sender.