Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Jul 9, 2024
1 parent 96fd9f3 commit 1df4503
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
3 changes: 1 addition & 2 deletions core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,7 @@ func Head(val interface{}) *evmtypes.Head {
}

func HeadWithHash(n int64, hash common.Hash) *evmtypes.Head {
var h evmtypes.Head
h = evmtypes.NewHead(big.NewInt(n), hash, evmutils.NewHash(), ubig.New(&FixtureChainID))
h := evmtypes.NewHead(big.NewInt(n), hash, evmutils.NewHash(), ubig.New(&FixtureChainID))
return &h
}

Expand Down
4 changes: 4 additions & 0 deletions core/services/relay/evm/mercury/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/libocr/offchainreporting2plus/chains/evmutil"
Expand Down Expand Up @@ -183,6 +184,9 @@ func SetupTH(t *testing.T, feedID common.Hash) TestHarness {
require.NoError(t, err)

configPoller.Start()
t.Cleanup(func() {
assert.NoError(t, configPoller.Close())
})

return TestHarness{
configPoller: configPoller,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestMeasureFulfillmentGasCost(t *testing.T) {
proofBlob, err := vrftesthelpers.GenerateProofResponseFromProof(proof, s)
require.NoError(t, err, "could not generate VRF proof!")
coordinator.Backend.Commit() // Work around simbackend/EVM block number bug
estimate := estimateGas(t, coordinator.Backend, coordinator.Neil.From,
estimate := estimateGas(t, coordinator.Backend.Client(), coordinator.Neil.From,
coordinator.RootContractAddress, coordinator.CoordinatorABI,
"fulfillRandomnessRequest", proofBlob[:])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ func deployVRFContract(t *testing.T) (contract, common.Address) {
// estimateGas returns the estimated gas cost of running the given method on the
// contract at address to, on the given backend, with the given args, and given
// that the transaction is sent from the from address.
func estimateGas(t *testing.T, backend *simulated.Backend,
func estimateGas(t *testing.T, client simulated.Client,
from, to common.Address, abi *abi.ABI, method string, args ...interface{},
) uint64 {
rawData, err := abi.Pack(method, args...)
require.NoError(t, err, "failed to construct raw %s transaction with args %s",
method, args)
callMsg := ethereum.CallMsg{From: from, To: &to, Data: rawData}
estimate, err := backend.Client().EstimateGas(testutils.Context(t), callMsg)
estimate, err := client.EstimateGas(testutils.Context(t), callMsg)
require.NoError(t, err, "failed to estimate gas from %s call with args %s",
method, args)
return estimate
}

func measureHashToCurveGasCost(t *testing.T, contract contract,
owner common.Address, input int64) (gasCost, numOrdinates uint64) {
estimate := estimateGas(t, contract.backend, owner, contract.address,
estimate := estimateGas(t, contract.backend.Client(), owner, contract.address,
contract.abi, "hashToCurve_", pair(secp256k1.Coordinates(vrfkey.Generator)),
big.NewInt(input))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestMeasureRandomValueFromVRFProofGasCost(t *testing.T) {
require.NoError(t, err, "failed to marshal VRF proof for on-chain verification")
contract, _ := deployVRFContract(t)

estimate := estimateGas(t, contract.backend, common.Address{},
estimate := estimateGas(t, contract.backend.Client(), common.Address{},
contract.address, contract.abi, "randomValueFromVRFProof_", mproof[:])

require.NoError(t, err, "failed to estimate gas cost for VRF verification")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
)

func TestMeasureRandomnessRequestGasCost(t *testing.T) {
t.Skip("TODO FIXME")
key := cltest.MustGenerateRandomKey(t)
coordinator := vrftesthelpers.NewVRFCoordinatorUniverse(t, key)
keyHash_, _, fee := registerProvingKey(t, coordinator)

estimate := estimateGas(t, coordinator.Backend, common.Address{},
estimate := estimateGas(t, coordinator.Backend.Client(), common.Address{},
coordinator.ConsumerContractAddress, coordinator.ConsumerABI,
"testRequestRandomness", common.BytesToHash(keyHash_[:]), fee)

Expand Down
4 changes: 2 additions & 2 deletions core/services/vrf/v2/listener_v2_log_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/services/servicetest"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker"
Expand Down Expand Up @@ -184,7 +185,6 @@ func setupVRFLogPollerListenerTH(t *testing.T,
*/

func TestInitProcessedBlock_NoVRFReqs(t *testing.T) {
t.Skip("TODO FIXME")
t.Parallel()
ctx := tests.Context(t)

Expand Down Expand Up @@ -212,7 +212,7 @@ func TestInitProcessedBlock_NoVRFReqs(t *testing.T) {
// Blocks till now: 2 (in SetupTH) + 2 (empty blocks) + 5 (EmitLog blocks) = 9

// Calling Start() after RegisterFilter() simulates a node restart after job creation, should reload Filter from db.
require.NoError(t, th.LogPoller.Start(testutils.Context(t)))
servicetest.Run(t, th.LogPoller)

// The poller starts on a new chain at latest-finality (finalityDepth + 5 in this case),
// Replaying from block 4 should guarantee we have block 4 immediately. (We will also get
Expand Down

0 comments on commit 1df4503

Please sign in to comment.