diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7fd855b330..39c8cc6d2f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -192,7 +192,7 @@ jobs: retries=0 while [ $retries -lt $max_num_retries ]; do - if $PYROSCOPE_PATH exec --apiKey=${{ secrets.PYROSCOPE_CLOUD_TOKEN }} -- gotestsum --rerun-fails=3 --packages="$pkg" --format standard-verbose -- -v -coverpkg="$pkg" -coverprofile=profile.cov $pkg; then + if $PYROSCOPE_PATH exec --apiKey=${{ secrets.PYROSCOPE_CLOUD_TOKEN }} -- gotestsum --rerun-fails=3 --packages="$pkg" --format standard-verbose -- -v -timeout 30m -coverpkg="$pkg" -coverprofile=profile.cov $pkg; then break else retries=$((retries+1)) diff --git a/agents/agents/executor/executor.go b/agents/agents/executor/executor.go index 1f96ad7993..d4d896b1b2 100644 --- a/agents/agents/executor/executor.go +++ b/agents/agents/executor/executor.go @@ -91,6 +91,8 @@ type Executor struct { retryConfig []retry.WithBackoffConfigurator // NowFunc returns the current time. NowFunc func() time.Time + // GetChainTimeFunc gets the chain time. + GetChainTimeFunc func(ctx context.Context, backend Backend) (uint64, error) } // logOrderInfo is a struct to keep track of the order of a log. @@ -240,16 +242,17 @@ func NewExecutor(ctx context.Context, config executor.Config, executorDB db.Exec } return &Executor{ - config: config, - executorDB: executorDB, - grpcConn: conn, - grpcClient: grpcClient, - signer: executorSigner, - chainExecutors: chainExecutors, - handler: handler, - txSubmitter: txSubmitter, - retryConfig: retryConfig, - NowFunc: time.Now, + config: config, + executorDB: executorDB, + grpcConn: conn, + grpcClient: grpcClient, + signer: executorSigner, + chainExecutors: chainExecutors, + handler: handler, + txSubmitter: txSubmitter, + retryConfig: retryConfig, + NowFunc: time.Now, + GetChainTimeFunc: getChainTime, }, nil } @@ -325,6 +328,7 @@ func (e Executor) Execute(parentCtx context.Context, message types.Message) (_ b ctx, span := e.handler.Tracer().Start(parentCtx, "Execute", trace.WithAttributes( attribute.Int(metrics.Origin, int(originDomain)), attribute.Int(metrics.Destination, int(destinationDomain)), + attribute.Int("message_type", int(message.Header().Flag())), )) defer func() { @@ -560,28 +564,28 @@ func (e Executor) verifyMessageOptimisticPeriod(parentCtx context.Context, messa return nil, nil } - var currentTime uint64 - chainCall := func(ctx context.Context) error { - var err error - latestHeader, err := e.chainExecutors[chainID].rpcClient.HeaderByNumber(ctx, nil) + var chainTime uint64 + call := func(ctx context.Context) error { + chainTime, err = e.GetChainTimeFunc(ctx, e.chainExecutors[chainID].rpcClient) if err != nil { - return fmt.Errorf("could not get latest header: %w", err) - } - - if latestHeader == nil { - return fmt.Errorf("latest header is nil") + return fmt.Errorf("could not get chain time: %w", err) } - - currentTime = latestHeader.Time - return nil } - err = retry.WithBackoff(ctx, chainCall, e.retryConfig...) + err = retry.WithBackoff(ctx, call, e.retryConfig...) if err != nil { return nil, fmt.Errorf("could not get latest header: %w", err) } - if *messageMinimumTime > currentTime { + span.AddEvent("got current time", trace.WithAttributes( + attribute.Int("chain_time", int(chainTime)), + )) + + if *messageMinimumTime > chainTime { + span.AddEvent("message is not old enough", trace.WithAttributes( + attribute.Int("message_minimum_time", int(*messageMinimumTime)), + attribute.Int("chain_time", int(chainTime)), + )) //nolint:nilnil return nil, nil } @@ -589,6 +593,21 @@ func (e Executor) verifyMessageOptimisticPeriod(parentCtx context.Context, messa return &nonce, nil } +func getChainTime(ctx context.Context, backend Backend) (uint64, error) { + var chainTime uint64 + latestHeader, err := backend.HeaderByNumber(ctx, nil) + if err != nil { + return chainTime, fmt.Errorf("could not get latest header: %w", err) + } + + if latestHeader == nil { + return chainTime, fmt.Errorf("latest header is nil") + } + + chainTime = latestHeader.Time + return chainTime, nil +} + // newTreeFromDB creates a new merkle tree from the database's messages. func newTreeFromDB(ctx context.Context, chainID uint32, executorDB db.ExecutorDB) (*merkle.HistoricalTree, error) { var allMessages []types.Message diff --git a/agents/agents/executor/executor_test.go b/agents/agents/executor/executor_test.go index f060c7e8b9..00c7fb8e87 100644 --- a/agents/agents/executor/executor_test.go +++ b/agents/agents/executor/executor_test.go @@ -626,14 +626,6 @@ func (e *ExecutorSuite) TestExecutor() { err = e.ExecutorTestDB.StoreAttestation(e.GetTestContext(), destinationAttestation, destination, 1, 1) e.Nil(err) - mask := execTypes.DBMessage{ - ChainID: &chainID, - Destination: &destination, - } - executableMessages, err := e.ExecutorTestDB.GetExecutableMessages(e.GetTestContext(), mask, uint64(time.Now().Unix()), 1) - e.Nil(err) - e.Len(executableMessages, 0) - // Make sure there is one executable message in the database. e.Eventually(func() bool { mask := execTypes.DBMessage{ @@ -797,6 +789,9 @@ func (e *ExecutorSuite) TestSetMinimumTime() { //nolint:maintidx func (e *ExecutorSuite) TestSendManagerMessage() { + // This test requires a call to anvil's evm.IncreaseTime() cheat code, so we should + // set up the backends with anvil. + testDone := false defer func() { testDone = true diff --git a/agents/agents/guard/fraud.go b/agents/agents/guard/fraud.go index 62acf4e9ad..b4af9f01fa 100644 --- a/agents/agents/guard/fraud.go +++ b/agents/agents/guard/fraud.go @@ -334,21 +334,26 @@ func (g Guard) handleStatusUpdated(ctx context.Context, log ethTypes.Log, chainI //nolint:exhaustive switch types.AgentFlagType(statusUpdated.Flag) { case types.AgentFlagFraudulent: - var agentProof [][32]byte - contractCall := func(ctx context.Context) error { - agentProof, err = g.domains[g.summitDomainID].BondingManager().GetProof(ctx, statusUpdated.Agent) - if err != nil { - return fmt.Errorf("could not get proof: %w", err) - } - + // Only perform completeSlashing for notary fraud. + if statusUpdated.Domain == 0 { return nil } - err = retry.WithBackoff(ctx, contractCall, g.retryConfig...) - if err != nil { - return fmt.Errorf("could not get proof: %w", err) - } + // Submit completeSlashing() tx after fetching agent proof. _, err = g.txSubmitter.SubmitTransaction(ctx, big.NewInt(int64(g.summitDomainID)), func(transactor *bind.TransactOpts) (tx *ethTypes.Transaction, err error) { + var agentProof [][32]byte + contractCall := func(ctx context.Context) error { + agentProof, err = g.domains[g.summitDomainID].BondingManager().GetProof(ctx, statusUpdated.Agent) + if err != nil { + return fmt.Errorf("could not get proof: %w", err) + } + + return nil + } + err = retry.WithBackoff(ctx, contractCall, g.retryConfig...) + if err != nil { + return nil, fmt.Errorf("could not get proof: %w", err) + } tx, err = g.domains[g.summitDomainID].BondingManager().CompleteSlashing( transactor, statusUpdated.Domain, @@ -362,7 +367,7 @@ func (g Guard) handleStatusUpdated(ctx context.Context, log ethTypes.Log, chainI return }) if err != nil { - return fmt.Errorf("could not submit CompleteSlashing tx: %w", err) + return fmt.Errorf("could not submit completeSlashing tx: %w", err) } case types.AgentFlagSlashed: var agentRoot [32]byte diff --git a/agents/agents/guard/fraud_test.go b/agents/agents/guard/fraud_test.go index 60ba061b02..4bea3a9483 100644 --- a/agents/agents/guard/fraud_test.go +++ b/agents/agents/guard/fraud_test.go @@ -1,6 +1,7 @@ package guard_test import ( + "context" "fmt" "math/big" "time" @@ -31,7 +32,7 @@ import ( "github.com/synapsecns/sanguine/services/scribe/service" ) -func (g GuardSuite) getTestGuard(scribeConfig scribeConfig.Config) (testGuard *guard.Guard, sclient client.ScribeClient, err error) { +func (g *GuardSuite) getTestGuard(scribeConfig scribeConfig.Config) (testGuard *guard.Guard, sclient client.ScribeClient, err error) { testConfig := config.AgentConfig{ Domains: map[string]config.DomainConfig{ "origin_client": g.OriginDomainClient.Config(), @@ -87,7 +88,7 @@ func (g GuardSuite) getTestGuard(scribeConfig scribeConfig.Config) (testGuard *g return testGuard, sclient, nil } -func (g GuardSuite) bumpBackends() { +func (g *GuardSuite) bumpBackends() { txContextSummit := g.TestBackendSummit.GetTxContext(g.GetTestContext(), g.SummitMetadata.OwnerPtr()) txContextOrigin := g.TestBackendOrigin.GetTxContext(g.GetTestContext(), g.OriginContractMetadata.OwnerPtr()) txContextDestination := g.TestBackendDestination.GetTxContext(g.GetTestContext(), g.DestinationContractMetadata.OwnerPtr()) @@ -97,13 +98,13 @@ func (g GuardSuite) bumpBackends() { } // Helper to get the test backend to emit expected events. -func (g GuardSuite) bumpBackend(backend backends.SimulatedTestBackend, contract *agentstestcontract.AgentsTestContractRef, txOpts *bind.TransactOpts) { +func (g *GuardSuite) bumpBackend(backend backends.SimulatedTestBackend, contract *agentstestcontract.AgentsTestContractRef, txOpts *bind.TransactOpts) { bumpTx, err := contract.EmitAgentsEventA(txOpts, big.NewInt(gofakeit.Int64()), big.NewInt(gofakeit.Int64()), big.NewInt(gofakeit.Int64())) Nil(g.T(), err) backend.WaitForConfirmation(g.GetTestContext(), bumpTx) } -func (g GuardSuite) updateAgentStatus(lightManager domains.LightManagerContract, bondedSigner, unbondedSigner signer.Signer, chainID uint32) { +func (g *GuardSuite) updateAgentStatus(lightManager domains.LightManagerContract, bondedSigner, unbondedSigner signer.Signer, chainID uint32) { agentStatus, err := g.SummitDomainClient.BondingManager().GetAgentStatus(g.GetTestContext(), bondedSigner.Address()) Nil(g.T(), err) agentProof, err := g.SummitDomainClient.BondingManager().GetProof(g.GetTestContext(), bondedSigner.Address()) @@ -121,7 +122,7 @@ func (g GuardSuite) updateAgentStatus(lightManager domains.LightManagerContract, } // TODO: Add a test for exiting the report logic early when the snapshot submitter is a guard. -func (g GuardSuite) TestFraudulentStateInSnapshot() { +func (g *GuardSuite) TestFraudulentStateInSnapshot() { testDone := false defer func() { testDone = true @@ -257,7 +258,7 @@ func (g GuardSuite) TestFraudulentStateInSnapshot() { g.verifyStateReport(g.LightInboxOnDestination, 1, fraudulentState) } -func (g GuardSuite) TestFraudulentAttestationOnDestination() { +func (g *GuardSuite) TestFraudulentAttestationOnDestination() { testDone := false defer func() { testDone = true @@ -380,7 +381,7 @@ func (g GuardSuite) TestFraudulentAttestationOnDestination() { }) } -func (g GuardSuite) TestReportFraudulentStateInAttestation() { +func (g *GuardSuite) TestReportFraudulentStateInAttestation() { testDone := false defer func() { testDone = true @@ -521,7 +522,7 @@ type statementInboxContract interface { // Verify that a state report was submitted on the given contract. // //nolint:unparam -func (g GuardSuite) verifyStateReport(contract statementInboxContract, expectedNumReports int64, expectedState types.State) { +func (g *GuardSuite) verifyStateReport(contract statementInboxContract, expectedNumReports int64, expectedState types.State) { g.Eventually(func() bool { numReports, err := contract.GetReportsAmount(&bind.CallOpts{Context: g.GetTestContext()}) Nil(g.T(), err) @@ -543,7 +544,7 @@ func (g GuardSuite) verifyStateReport(contract statementInboxContract, expectedN }) } -func (g GuardSuite) TestInvalidReceipt() { +func (g *GuardSuite) TestInvalidReceipt() { testDone := false defer func() { testDone = true @@ -720,7 +721,10 @@ func (g GuardSuite) TestInvalidReceipt() { } //nolint:maintidx,cyclop -func (g GuardSuite) TestUpdateAgentStatusOnRemote() { +func (g *GuardSuite) TestUpdateAgentStatusOnRemote() { + // This test requires a call to anvil's evm.IncreaseTime() cheat code, so we should + // set up the backends with anvil. + testDone := false defer func() { testDone = true @@ -838,11 +842,15 @@ func (g GuardSuite) TestUpdateAgentStatusOnRemote() { } return *currentTime } + getChainTimeFunc := func(ctx context.Context, backend executor.Backend) (uint64, error) { + return uint64(nowFunc().Unix()), nil + } // Start a new Executor. exec, err := executor.NewExecutor(g.GetTestContext(), excCfg, g.ExecutorTestDB, scribeClient, omniRPCClient, g.ExecutorMetrics) Nil(g.T(), err) exec.NowFunc = nowFunc + exec.GetChainTimeFunc = getChainTimeFunc go func() { execErr := exec.Run(g.GetTestContext()) @@ -1024,6 +1032,8 @@ func (g GuardSuite) TestUpdateAgentStatusOnRemote() { Nil(g.T(), err) err = anvilClient.IncreaseTime(g.GetTestContext(), seconds) Nil(g.T(), err) + err = anvilClient.Mine(g.GetTestContext(), 1) + Nil(g.T(), err) } increaseEvmTime(g.TestBackendSummit, optimisticPeriodSeconds+offset) g.bumpBackends() diff --git a/agents/go.mod b/agents/go.mod index c49d685a7f..b4151a6627 100644 --- a/agents/go.mod +++ b/agents/go.mod @@ -43,8 +43,16 @@ require ( require ( dario.cat/mergo v1.0.0 // indirect + github.com/deepmap/oapi-codegen v1.8.2 // indirect + github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect + github.com/graph-gophers/graphql-go v1.3.0 // indirect + github.com/influxdata/influxdb v1.8.3 // indirect + github.com/influxdata/influxdb-client-go/v2 v2.5.1 // indirect + github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect github.com/jpillora/backoff v1.0.0 // indirect + github.com/peterh/liner v1.2.1 // indirect github.com/puzpuzpuz/xsync/v2 v2.5.1 // indirect + github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 // indirect ) require ( diff --git a/agents/go.sum b/agents/go.sum index 1d983338d2..2f426f6973 100644 --- a/agents/go.sum +++ b/agents/go.sum @@ -646,6 +646,7 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/graph-gophers/graphql-go v0.0.0-20201113091052-beb923fada29/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY41SORZyNJ0= +github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= @@ -736,6 +737,7 @@ github.com/influxdata/influxdb v1.8.3 h1:WEypI1BQFTT4teLM+1qkEcvUi0dAvopAI/ir0vA github.com/influxdata/influxdb v1.8.3/go.mod h1:JugdFhsvvI8gadxOI6noqNeeBHvWNTbfYGtiAn+2jhI= github.com/influxdata/influxdb-client-go/v2 v2.4.0/go.mod h1:vLNHdxTJkIf2mSLvGrpj8TCcISApPoXkaxP8g9uRlW8= github.com/influxdata/influxdb-client-go/v2 v2.5.1 h1:ytMbX2YeupSsec1Exp3zALTjvfhXkvxcyV6nOXkjG3s= +github.com/influxdata/influxdb-client-go/v2 v2.5.1/go.mod h1:Y/0W1+TZir7ypoQZYd2IrnVOKB3Tq6oegAQeSVN/+EU= github.com/influxdata/influxdb1-client v0.0.0-20190809212627-fc22c7df067e/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/influxdata/influxql v1.1.1-0.20200828144457-65d3ef77d385/go.mod h1:gHp9y86a/pxhjJ+zMjNXiQAA197Xk9wLxaz+fGG+kWk= github.com/influxdata/line-protocol v0.0.0-20180522152040-32c6aa80de5e/go.mod h1:4kt73NQhadE3daL3WhR5EJ/J2ocX0PZzwxQ0gXJ7oFE= @@ -797,6 +799,7 @@ github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0= github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= @@ -1023,6 +1026,7 @@ github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNc github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/peterh/liner v1.2.1 h1:O4BlKaq/LWu6VRWmol4ByWfzx6MfXc5Op5HETyIy5yg= +github.com/peterh/liner v1.2.1/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= @@ -1180,6 +1184,7 @@ github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiu github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/status-im/keycard-go v0.0.0-20191119114148-6dd40a46baa0/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 h1:Oo2KZNP70KE0+IUJSidPj/BFS/RXNHmKIJOdckzml2E= +github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw= github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/agents/testutil/simulated_backends_suite.go b/agents/testutil/simulated_backends_suite.go index 67628d2488..ca76c6b566 100644 --- a/agents/testutil/simulated_backends_suite.go +++ b/agents/testutil/simulated_backends_suite.go @@ -42,6 +42,7 @@ import ( "github.com/synapsecns/sanguine/core/testsuite" "github.com/synapsecns/sanguine/ethergo/backends" "github.com/synapsecns/sanguine/ethergo/backends/anvil" + "github.com/synapsecns/sanguine/ethergo/backends/preset" "github.com/synapsecns/sanguine/ethergo/chain/client" "github.com/synapsecns/sanguine/ethergo/contracts" "github.com/synapsecns/sanguine/ethergo/signer/signer" @@ -355,41 +356,98 @@ func (a *SimulatedBackendsTestSuite) SetupExecutor() { a.ExecutorUnbondedSigner = localsigner.NewSigner(a.ExecutorUnbondedWallet.PrivateKey()) } +// Tests included here will use an anvil backend (instead of ethergo). +var anvilTests = []string{ + "TestGuardSuite/TestUpdateAgentStatusOnRemote", + "TestExecutorSuite/TestSendManagerMessage", +} + +func (a *SimulatedBackendsTestSuite) shouldUseAnvil() bool { + for _, test := range anvilTests { + if a.T().Name() == test { + return true + } + } + return false +} + // SetupTest sets up the test. func (a *SimulatedBackendsTestSuite) SetupTest() { a.TestSuite.SetupTest() - a.TestSuite.DeferAfterSuite(a.cleanAfterTestSuite) + a.TestSuite.DeferAfterTest(a.cleanAfterTestSuite) a.SetupGuard() a.SetupNotary() a.SetupNotaryOnOrigin() a.SetupNotaryOnDestination() a.SetupExecutor() + a.SetupBackends() + + a.DBPath = filet.TmpDir(a.T(), "") + scribeSqliteStore, err := scribesqlite.NewSqliteStore(a.GetTestContext(), a.DBPath, a.ScribeMetrics, false) + if err != nil { + a.T().Fatal(err) + } + a.ScribeTestDB = scribeSqliteStore + sqliteStore, err := executorsqllite.NewSqliteStore(a.GetTestContext(), a.DBPath, a.ExecutorMetrics, false) + if err != nil { + a.T().Fatal(err) + } + a.ExecutorTestDB = sqliteStore + notarySqliteStore, err := notarySqlite.NewSqliteStore(a.GetTestContext(), a.DBPath, a.NotaryMetrics, false) + if err != nil { + a.T().Fatal(err) + } + a.NotaryTestDB = notarySqliteStore + guardSqliteStore, err := guardSqlite.NewSqliteStore(a.GetTestContext(), a.DBPath, a.GuardMetrics, false) + if err != nil { + a.T().Fatal(err) + } + a.GuardTestDB = guardSqliteStore +} +// SetupBackends sets up the simulated backends. +func (a *SimulatedBackendsTestSuite) SetupBackends() { + useAnvil := a.shouldUseAnvil() a.TestDeployManager = NewDeployManager(a.T()) var wg sync.WaitGroup wg.Add(3) go func() { defer wg.Done() - anvilOptsOrigin := anvil.NewAnvilOptionBuilder() - anvilOptsOrigin.SetChainID(uint64(params.RinkebyChainConfig.ChainID.Int64())) - anvilOptsOrigin.SetBlockTime(1 * time.Second) - a.TestBackendOrigin = anvil.NewAnvilBackend(a.GetTestContext(), a.T(), anvilOptsOrigin) + if useAnvil { + anvilOptsOrigin := anvil.NewAnvilOptionBuilder() + anvilOptsOrigin.SetChainID(uint64(params.RinkebyChainConfig.ChainID.Int64())) + anvilOptsOrigin.SetBlockTime(1 * time.Second) + a.TestBackendOrigin = anvil.NewAnvilBackend(a.GetTestContext(), a.T(), anvilOptsOrigin) + a.TestSuite.DeferAfterTest(a.TestBackendOrigin.(*anvil.Backend).TearDown) + } else { + a.TestBackendOrigin = preset.GetRinkeby().Geth(a.GetTestContext(), a.T()) + } }() go func() { defer wg.Done() - anvilOptsDestination := anvil.NewAnvilOptionBuilder() - anvilOptsDestination.SetChainID(uint64(client.ChapelChainConfig.ChainID.Int64())) - anvilOptsDestination.SetBlockTime(1 * time.Second) - a.TestBackendDestination = anvil.NewAnvilBackend(a.GetTestContext(), a.T(), anvilOptsDestination) + if useAnvil { + anvilOptsDestination := anvil.NewAnvilOptionBuilder() + anvilOptsDestination.SetChainID(uint64(client.ChapelChainConfig.ChainID.Int64())) + anvilOptsDestination.SetBlockTime(1 * time.Second) + a.TestBackendDestination = anvil.NewAnvilBackend(a.GetTestContext(), a.T(), anvilOptsDestination) + a.TestSuite.DeferAfterTest(a.TestBackendDestination.(*anvil.Backend).TearDown) + } else { + a.TestBackendDestination = preset.GetBSCTestnet().Geth(a.GetTestContext(), a.T()) + } }() go func() { defer wg.Done() - anvilOptsSummit := anvil.NewAnvilOptionBuilder() - anvilOptsSummit.SetChainID(uint64(10)) - anvilOptsSummit.SetBlockTime(1 * time.Second) - a.TestBackendSummit = anvil.NewAnvilBackend(a.GetTestContext(), a.T(), anvilOptsSummit) + if useAnvil { + anvilOptsSummit := anvil.NewAnvilOptionBuilder() + anvilOptsSummit.SetChainID(uint64(10)) + anvilOptsSummit.SetBlockTime(1 * time.Second) + a.TestBackendSummit = anvil.NewAnvilBackend(a.GetTestContext(), a.T(), anvilOptsSummit) + a.TestSuite.DeferAfterTest(a.TestBackendSummit.(*anvil.Backend).TearDown) + } else { + a.TestBackendSummit = preset.GetMaticMumbaiFakeSynDomain().Geth(a.GetTestContext(), a.T()) + } }() wg.Wait() @@ -425,28 +483,6 @@ func (a *SimulatedBackendsTestSuite) SetupTest() { if err != nil { a.T().Fatal(err) } - - a.DBPath = filet.TmpDir(a.T(), "") - scribeSqliteStore, err := scribesqlite.NewSqliteStore(a.GetTestContext(), a.DBPath, a.ScribeMetrics, false) - if err != nil { - a.T().Fatal(err) - } - a.ScribeTestDB = scribeSqliteStore - sqliteStore, err := executorsqllite.NewSqliteStore(a.GetTestContext(), a.DBPath, a.ExecutorMetrics, false) - if err != nil { - a.T().Fatal(err) - } - a.ExecutorTestDB = sqliteStore - notarySqliteStore, err := notarySqlite.NewSqliteStore(a.GetTestContext(), a.DBPath, a.NotaryMetrics, false) - if err != nil { - a.T().Fatal(err) - } - a.NotaryTestDB = notarySqliteStore - guardSqliteStore, err := guardSqlite.NewSqliteStore(a.GetTestContext(), a.DBPath, a.GuardMetrics, false) - if err != nil { - a.T().Fatal(err) - } - a.GuardTestDB = guardSqliteStore } // cleanAfterTestSuite does cleanup after test suite is finished. diff --git a/ethergo/backends/anvil/anvil.go b/ethergo/backends/anvil/anvil.go index 64695207d6..f12803f1d5 100644 --- a/ethergo/backends/anvil/anvil.go +++ b/ethergo/backends/anvil/anvil.go @@ -51,13 +51,17 @@ type Backend struct { chainConfig *params.ChainConfig // impersonationMux is used to lock the impersonation impersonationMux sync.Mutex + // pool is the docker pool + pool *dockertest.Pool + // resource is the docker resource + resource *dockertest.Resource } // BackendName is the name of the anvil backend. const BackendName = "anvil" // BackendName returns the name of the backend. -func (f *Backend) BackendName() string { +func (b *Backend) BackendName() string { return BackendName } @@ -170,6 +174,8 @@ func NewAnvilBackend(ctx context.Context, t *testing.T, args *OptionBuilder) *Ba fundingMux: mapmutex.NewStringerMapMutex(), store: base.NewInMemoryKeyStore(), chainConfig: chainConfig, + pool: pool, + resource: resource, } err = backend.storeWallets(args) @@ -178,10 +184,7 @@ func NewAnvilBackend(ctx context.Context, t *testing.T, args *OptionBuilder) *Ba t.Cleanup(func() { select { case <-ctx.Done(): - err = pool.Purge(resource) - if err != nil { - logger.Errorf("error purging anvil container: %w", err) - } + backend.TearDown() default: // do nothing, we don't want to purge the container if this is just a subtest } @@ -190,6 +193,14 @@ func NewAnvilBackend(ctx context.Context, t *testing.T, args *OptionBuilder) *Ba return &backend } +// TearDown purges docker resources associated with the backend. +func (b *Backend) TearDown() { + err := b.pool.Purge(b.resource) + if err != nil { + logger.Errorf("error purging anvil container: %w", err) + } +} + func setupOtterscan(ctx context.Context, tb testing.TB, pool *dockertest.Pool, anvilResource *dockertest.Resource, args *OptionBuilder) string { tb.Helper() diff --git a/services/sinner/go.mod b/services/sinner/go.mod index 62ee7ee175..2786cbfb24 100644 --- a/services/sinner/go.mod +++ b/services/sinner/go.mod @@ -112,6 +112,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set v1.8.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect + github.com/deepmap/oapi-codegen v1.8.2 // indirect github.com/dgrr/http2 v0.3.5 // indirect github.com/disintegration/imaging v1.6.2 // indirect github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 // indirect @@ -129,6 +130,7 @@ require ( github.com/flynn/json5 v0.0.0-20160717195620-7620272ed633 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect github.com/gin-contrib/cors v1.4.0 // indirect github.com/gin-contrib/requestid v0.0.6 // indirect github.com/gin-contrib/sse v0.1.0 // indirect @@ -162,6 +164,7 @@ require ( github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/gax-go/v2 v2.8.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect + github.com/graph-gophers/graphql-go v1.3.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-bexpr v0.1.10 // indirect @@ -179,6 +182,9 @@ require ( github.com/imdario/mergo v0.3.13 // indirect github.com/imkira/go-interpol v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/influxdata/influxdb v1.8.3 // indirect + github.com/influxdata/influxdb-client-go/v2 v2.5.1 // indirect + github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect github.com/invopop/jsonschema v0.7.0 // indirect github.com/ipfs/go-log/v2 v2.1.3 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect @@ -228,6 +234,7 @@ require ( github.com/palantir/pkg/transform v1.0.0 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/peterh/liner v1.2.1 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pkg/term v1.2.0-beta.2 // indirect @@ -261,6 +268,7 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.12.0 // indirect + github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 // indirect github.com/subosito/gotenv v1.4.0 // indirect github.com/synapsecns/fasthttp-http2 v1.0.0 // indirect github.com/synapsecns/sanguine/services/omnirpc v0.0.0-00010101000000-000000000000 // indirect diff --git a/services/sinner/go.sum b/services/sinner/go.sum index 465155185c..e891a409b9 100644 --- a/services/sinner/go.sum +++ b/services/sinner/go.sum @@ -642,6 +642,7 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/graph-gophers/graphql-go v0.0.0-20201113091052-beb923fada29/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY41SORZyNJ0= +github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= @@ -731,6 +732,7 @@ github.com/influxdata/influxdb v1.8.3 h1:WEypI1BQFTT4teLM+1qkEcvUi0dAvopAI/ir0vA github.com/influxdata/influxdb v1.8.3/go.mod h1:JugdFhsvvI8gadxOI6noqNeeBHvWNTbfYGtiAn+2jhI= github.com/influxdata/influxdb-client-go/v2 v2.4.0/go.mod h1:vLNHdxTJkIf2mSLvGrpj8TCcISApPoXkaxP8g9uRlW8= github.com/influxdata/influxdb-client-go/v2 v2.5.1 h1:ytMbX2YeupSsec1Exp3zALTjvfhXkvxcyV6nOXkjG3s= +github.com/influxdata/influxdb-client-go/v2 v2.5.1/go.mod h1:Y/0W1+TZir7ypoQZYd2IrnVOKB3Tq6oegAQeSVN/+EU= github.com/influxdata/influxdb1-client v0.0.0-20190809212627-fc22c7df067e/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/influxdata/influxql v1.1.1-0.20200828144457-65d3ef77d385/go.mod h1:gHp9y86a/pxhjJ+zMjNXiQAA197Xk9wLxaz+fGG+kWk= github.com/influxdata/line-protocol v0.0.0-20180522152040-32c6aa80de5e/go.mod h1:4kt73NQhadE3daL3WhR5EJ/J2ocX0PZzwxQ0gXJ7oFE= @@ -791,6 +793,7 @@ github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0= github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= @@ -1015,6 +1018,7 @@ github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNc github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/peterh/liner v1.2.1 h1:O4BlKaq/LWu6VRWmol4ByWfzx6MfXc5Op5HETyIy5yg= +github.com/peterh/liner v1.2.1/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= @@ -1167,6 +1171,7 @@ github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiu github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/status-im/keycard-go v0.0.0-20191119114148-6dd40a46baa0/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 h1:Oo2KZNP70KE0+IUJSidPj/BFS/RXNHmKIJOdckzml2E= +github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw= github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=