From 23856a6e54a0261c661ace09eaecd103ba68cdc1 Mon Sep 17 00:00:00 2001 From: Arnau Date: Wed, 30 Oct 2024 16:58:09 -0600 Subject: [PATCH] feat use sqlite on claimsponsor --- claimsponsor/claimsponsor.go | 371 ++++++------------- claimsponsor/e2e_test.go | 4 +- claimsponsor/evmclaimsponsor.go | 2 +- claimsponsor/migrations/claimsponsor0001.sql | 20 + claimsponsor/migrations/migrations.go | 23 ++ rpc/bridge.go | 4 +- rpc/bridge_interfaces.go | 4 +- rpc/mocks/claim_sponsorer.go | 52 ++- 8 files changed, 187 insertions(+), 293 deletions(-) create mode 100644 claimsponsor/migrations/claimsponsor0001.sql create mode 100644 claimsponsor/migrations/migrations.go diff --git a/claimsponsor/claimsponsor.go b/claimsponsor/claimsponsor.go index c9df6561..a212e4f1 100644 --- a/claimsponsor/claimsponsor.go +++ b/claimsponsor/claimsponsor.go @@ -2,33 +2,28 @@ package claimsponsor import ( "context" - "encoding/json" + "database/sql" "errors" - "math" + "fmt" "math/big" "time" - dbCommon "github.com/0xPolygon/cdk/common" + "github.com/0xPolygon/cdk/claimsponsor/migrations" "github.com/0xPolygon/cdk/db" "github.com/0xPolygon/cdk/log" "github.com/0xPolygon/cdk/sync" tree "github.com/0xPolygon/cdk/tree/types" "github.com/ethereum/go-ethereum/common" - "github.com/ledgerwatch/erigon-lib/kv" - "github.com/ledgerwatch/erigon-lib/kv/iter" - "github.com/ledgerwatch/erigon-lib/kv/mdbx" + "github.com/russross/meddler" ) type ClaimStatus string const ( - PendingClaimStatus = "pending" - WIPStatus = "work in progress" - SuccessClaimStatus = "success" - FailedClaimStatus = "failed" - - claimTable = "claimsponsor-tx" - queueTable = "claimsponsor-queue" + PendingClaimStatus ClaimStatus = "pending" + WIPClaimStatus ClaimStatus = "work in progress" + SuccessClaimStatus ClaimStatus = "success" + FailedClaimStatus ClaimStatus = "failed" ) var ( @@ -37,21 +32,20 @@ var ( // Claim representation of a claim event type Claim struct { - LeafType uint8 - ProofLocalExitRoot tree.Proof - ProofRollupExitRoot tree.Proof - GlobalIndex *big.Int - MainnetExitRoot common.Hash - RollupExitRoot common.Hash - OriginNetwork uint32 - OriginTokenAddress common.Address - DestinationNetwork uint32 - DestinationAddress common.Address - Amount *big.Int - Metadata []byte - - Status ClaimStatus - TxID string + LeafType uint8 `meddler:"leaf_type"` + ProofLocalExitRoot tree.Proof `meddler:"proof_local_exit_root,merkleproof"` + ProofRollupExitRoot tree.Proof `meddler:"proof_rollup_exit_root,merkleproof"` + GlobalIndex *big.Int `meddler:"global_index,bigint"` + MainnetExitRoot common.Hash `meddler:"mainnet_exit_root,hash"` + RollupExitRoot common.Hash `meddler:"rollup_exit_root,hash"` + OriginNetwork uint32 `meddler:"origin_network"` + OriginTokenAddress common.Address `meddler:"origin_token_address,address"` + DestinationNetwork uint32 `meddler:"destination_network"` + DestinationAddress common.Address `meddler:"destination_address,address"` + Amount *big.Int `meddler:"amount,bigint"` + Metadata []byte `meddler:"metadata"` + Status ClaimStatus `meddler:"status"` + TxID string `meddler:"tx_id"` } func (c *Claim) Key() []byte { @@ -66,7 +60,7 @@ type ClaimSender interface { type ClaimSponsor struct { logger *log.Logger - db kv.RwDB + db *sql.DB sender ClaimSender rh *sync.RetryHandler waitTxToBeMinedPeriod time.Duration @@ -82,18 +76,11 @@ func newClaimSponsor( waitTxToBeMinedPeriod time.Duration, waitOnEmptyQueue time.Duration, ) (*ClaimSponsor, error) { - tableCfgFunc := func(defaultBuckets kv.TableCfg) kv.TableCfg { - cfg := kv.TableCfg{ - claimTable: {}, - queueTable: {}, - } - - return cfg + err := migrations.RunMigrations(dbPath) + if err != nil { + return nil, err } - db, err := mdbx.NewMDBX(nil). - Path(dbPath). - WithTableCfg(tableCfgFunc). - Open() + db, err := db.NewSQLiteDB(dbPath) if err != nil { return nil, err } @@ -115,264 +102,132 @@ func newClaimSponsor( func (c *ClaimSponsor) Start(ctx context.Context) { var ( attempts int - err error ) for { + err := c.claim(ctx) if err != nil { attempts++ + c.logger.Error(err) c.rh.Handle("claimsponsor main loop", attempts) + } else { + attempts = 0 } - tx, err2 := c.db.BeginRw(ctx) - if err2 != nil { - err = err2 - c.logger.Errorf("error calling BeginRw: %v", err) - continue - } - queueIndex, globalIndex, err2 := getFirstQueueIndex(tx) - if err2 != nil { - err = err2 - tx.Rollback() - if errors.Is(err, db.ErrNotFound) { - c.logger.Debugf("queue is empty") - err = nil - time.Sleep(c.waitOnEmptyQueue) - - continue - } - c.logger.Errorf("error calling getFirstQueueIndex: %v", err) - continue - } - claim, err2 := getClaim(tx, globalIndex) - if err2 != nil { - err = err2 - tx.Rollback() - c.logger.Errorf("error calling getClaim with globalIndex %s: %v", globalIndex.String(), err) - continue - } - if claim.TxID == "" { - txID, err2 := c.sender.sendClaim(ctx, claim) - if err2 != nil { - err = err2 - tx.Rollback() - c.logger.Errorf("error calling sendClaim with globalIndex %s: %v", globalIndex.String(), err) - continue - } - claim.TxID = txID - claim.Status = WIPStatus - err2 = putClaim(tx, claim) - if err2 != nil { - err = err2 - tx.Rollback() - c.logger.Errorf("error calling putClaim with globalIndex %s: %v", globalIndex.String(), err) - continue - } - } - err2 = tx.Commit() - if err2 != nil { - err = err2 - c.logger.Errorf("error calling tx.Commit after putting claim: %v", err) - continue - } - - c.logger.Infof("waiting for tx %s with global index %s to succeed or fail", claim.TxID, globalIndex.String()) - status, err2 := c.waitTxToBeSuccessOrFail(ctx, claim.TxID) - if err2 != nil { - err = err2 - c.logger.Errorf("error calling waitTxToBeSuccessOrFail for tx %s: %v", claim.TxID, err) - continue - } - c.logger.Infof("tx %s with global index %s concluded with status: %s", claim.TxID, globalIndex.String(), status) - tx, err2 = c.db.BeginRw(ctx) - if err2 != nil { - err = err2 - c.logger.Errorf("error calling BeginRw: %v", err) - continue - } - claim.Status = status - err2 = putClaim(tx, claim) - if err2 != nil { - err = err2 - tx.Rollback() - c.logger.Errorf("error calling putClaim with globalIndex %s: %v", globalIndex.String(), err) - continue - } - err2 = tx.Delete(queueTable, dbCommon.Uint64ToBytes(queueIndex)) - if err2 != nil { - err = err2 - tx.Rollback() - c.logger.Errorf("error calling delete on the queue table with index %d: %v", queueIndex, err) - continue - } - err2 = tx.Commit() - if err2 != nil { - err = err2 - c.logger.Errorf("error calling tx.Commit after putting claim: %v", err) - continue - } - - attempts = 0 } } -func (c *ClaimSponsor) waitTxToBeSuccessOrFail(ctx context.Context, txID string) (ClaimStatus, error) { - t := time.NewTicker(c.waitTxToBeMinedPeriod) - for { - select { - case <-ctx.Done(): - return "", errors.New("context cancelled") - case <-t.C: - status, err := c.sender.claimStatus(ctx, txID) - if err != nil { - return "", err - } - if status == FailedClaimStatus || status == SuccessClaimStatus { - return status, nil +func (c *ClaimSponsor) claim(ctx context.Context) error { + claim, err := c.getWIPClaim() + if err != nil && !errors.Is(err, db.ErrNotFound) { + return fmt.Errorf("error getting WIP claim: %w", err) + } + if errors.Is(err, db.ErrNotFound) || claim == nil { + // there is no WIP claim, go for the next pending claim + claim, err = c.getFirstPendingClaim() + if err != nil { + if errors.Is(err, db.ErrNotFound) { + c.logger.Debugf("queue is empty") + time.Sleep(c.waitOnEmptyQueue) + return nil } + return fmt.Errorf("error calling getClaim with globalIndex %s: %w", claim.GlobalIndex.String(), err) } - } -} - -func (c *ClaimSponsor) AddClaimToQueue(ctx context.Context, claim *Claim) error { - if claim.GlobalIndex == nil { - return ErrInvalidClaim - } - claim.Status = PendingClaimStatus - tx, err := c.db.BeginRw(ctx) - if err != nil { - return err - } - - _, err = getClaim(tx, claim.GlobalIndex) - if !errors.Is(err, db.ErrNotFound) { + txID, err := c.sender.sendClaim(ctx, claim) if err != nil { - tx.Rollback() - - return err - } else { - tx.Rollback() - - return errors.New("claim already added") + return fmt.Errorf("error getting sending claim: %w", err) + } + if err := c.updateClaimTxID(claim.GlobalIndex, txID); err != nil { + return fmt.Errorf("error updating claim txID: %w", err) } } - err = putClaim(tx, claim) - if err != nil { - tx.Rollback() - - return err - } - - var queuePosition uint64 - lastQueuePosition, _, err := getLastQueueIndex(tx) - switch { - case errors.Is(err, db.ErrNotFound): - queuePosition = 0 - - case err != nil: - tx.Rollback() - - return err - - default: - queuePosition = lastQueuePosition + 1 - } - - err = tx.Put(queueTable, dbCommon.Uint64ToBytes(queuePosition), claim.Key()) + c.logger.Infof("waiting for tx %s with global index %s to succeed or fail", claim.TxID, claim.GlobalIndex.String()) + status, err := c.waitTxToBeSuccessOrFail(ctx, claim.TxID) if err != nil { - tx.Rollback() - - return err + return fmt.Errorf("error calling waitTxToBeSuccessOrFail for tx %s: %w", claim.TxID, err) } - - return tx.Commit() + c.logger.Infof("tx %s with global index %s concluded with status: %s", claim.TxID, claim.GlobalIndex.String(), status) + return c.updateClaimStatus(claim.GlobalIndex, status) } -func putClaim(tx kv.RwTx, claim *Claim) error { - value, err := json.Marshal(claim) - if err != nil { - return err - } +func (c *ClaimSponsor) getWIPClaim() (*Claim, error) { + claim := &Claim{} + return claim, meddler.QueryRow( + c.db, claim, + `SELECT claim_data FROM claim WHERE status = $1 ORDER BY rowid ASC LIMIT 1;`, + WIPClaimStatus, + ) +} - return tx.Put(claimTable, claim.Key(), value) +func (c *ClaimSponsor) getFirstPendingClaim() (*Claim, error) { + claim := &Claim{} + return claim, meddler.QueryRow( + c.db, claim, + `SELECT claim_data FROM claim WHERE status = $1 ORDER BY rowid ASC LIMIT 1;`, + PendingClaimStatus, + ) } -func (c *ClaimSponsor) getClaimByQueueIndex(ctx context.Context, queueIndex uint64) (*Claim, error) { - tx, err := c.db.BeginRo(ctx) +func (c *ClaimSponsor) updateClaimTxID(globalIndex *big.Int, txID string) error { + res, err := c.db.Exec( + `UPDATE claim SET tx_id = $1 WHERE global_index = $2`, + txID, globalIndex.String(), + ) if err != nil { - return nil, err + return fmt.Errorf("error updating claim status: %w", err) } - defer tx.Rollback() - - globalIndexBytes, err := tx.GetOne(queueTable, dbCommon.Uint64ToBytes(queueIndex)) + rowsAff, err := res.RowsAffected() if err != nil { - return nil, err + return fmt.Errorf("error getting rows affected: %w", err) } - if globalIndexBytes == nil { - return nil, db.ErrNotFound + if rowsAff == 0 { + return fmt.Errorf("the claim requested to be updated does not exist") } - - return getClaim(tx, new(big.Int).SetBytes(globalIndexBytes)) -} - -func getLastQueueIndex(tx kv.Tx) (uint64, *big.Int, error) { - iter, err := tx.RangeDescend( - queueTable, - dbCommon.Uint64ToBytes(math.MaxUint64), - dbCommon.Uint64ToBytes(0), 1, - ) - if err != nil { - return 0, nil, err - } - - return getIndex(iter) + return nil } -func getFirstQueueIndex(tx kv.Tx) (uint64, *big.Int, error) { - iter, err := tx.RangeAscend( - queueTable, - dbCommon.Uint64ToBytes(0), - nil, 1, +func (c *ClaimSponsor) updateClaimStatus(globalIndex *big.Int, status ClaimStatus) error { + res, err := c.db.Exec( + `UPDATE claim SET status = $1 WHERE global_index = $2`, + status, globalIndex.String(), ) if err != nil { - return 0, nil, err + return fmt.Errorf("error updating claim status: %w", err) } - - return getIndex(iter) -} - -func getIndex(iter iter.KV) (uint64, *big.Int, error) { - k, v, err := iter.Next() + rowsAff, err := res.RowsAffected() if err != nil { - return 0, nil, err + return fmt.Errorf("error getting rows affected: %w", err) } - if k == nil { - return 0, nil, db.ErrNotFound + if rowsAff == 0 { + return fmt.Errorf("the claim requested to be updated does not exist") } - globalIndex := new(big.Int).SetBytes(v) - - return dbCommon.BytesToUint64(k), globalIndex, nil + return nil } -func (c *ClaimSponsor) GetClaim(ctx context.Context, globalIndex *big.Int) (*Claim, error) { - tx, err := c.db.BeginRo(ctx) - if err != nil { - return nil, err +func (c *ClaimSponsor) waitTxToBeSuccessOrFail(ctx context.Context, txID string) (ClaimStatus, error) { + t := time.NewTicker(c.waitTxToBeMinedPeriod) + for { + select { + case <-ctx.Done(): + return "", errors.New("context cancelled") + case <-t.C: + status, err := c.sender.claimStatus(ctx, txID) + if err != nil { + return "", err + } + if status == FailedClaimStatus || status == SuccessClaimStatus { + return status, nil + } + } } - defer tx.Rollback() +} - return getClaim(tx, globalIndex) +func (c *ClaimSponsor) AddClaimToQueue(claim *Claim) error { + return meddler.Insert(c.db, "claim", claim) } -func getClaim(tx kv.Tx, globalIndex *big.Int) (*Claim, error) { - claimBytes, err := tx.GetOne(claimTable, globalIndex.Bytes()) - if err != nil { - return nil, err - } - if claimBytes == nil { - return nil, db.ErrNotFound - } +func (c *ClaimSponsor) GetClaim(globalIndex *big.Int) (*Claim, error) { claim := &Claim{} - err = json.Unmarshal(claimBytes, claim) - - return claim, err + return claim, meddler.QueryRow( + c.db, claim, `SELECT claim_data FROM claim WHERE global_index = $1`, globalIndex.String(), + ) } diff --git a/claimsponsor/e2e_test.go b/claimsponsor/e2e_test.go index b4fce499..4bc756c7 100644 --- a/claimsponsor/e2e_test.go +++ b/claimsponsor/e2e_test.go @@ -71,7 +71,7 @@ func TestE2EL1toEVML2(t *testing.T) { // Request to sponsor claim globalIndex := bridgesync.GenerateGlobalIndex(true, 0, uint32(i)) - err = claimer.AddClaimToQueue(ctx, &claimsponsor.Claim{ + err = claimer.AddClaimToQueue(&claimsponsor.Claim{ LeafType: 0, ProofLocalExitRoot: localProof, ProofRollupExitRoot: rollupProof, @@ -90,7 +90,7 @@ func TestE2EL1toEVML2(t *testing.T) { // Wait until success succeed := false for i := 0; i < 10; i++ { - claim, err := claimer.GetClaim(ctx, globalIndex) + claim, err := claimer.GetClaim(globalIndex) require.NoError(t, err) if claim.Status == claimsponsor.FailedClaimStatus { require.NoError(t, errors.New("claim failed")) diff --git a/claimsponsor/evmclaimsponsor.go b/claimsponsor/evmclaimsponsor.go index 12d0c4ca..6f315d94 100644 --- a/claimsponsor/evmclaimsponsor.go +++ b/claimsponsor/evmclaimsponsor.go @@ -168,7 +168,7 @@ func (c *EVMClaimSponsor) claimStatus(ctx context.Context, id string) (ClaimStat switch res.Status { case ethtxtypes.MonitoredTxStatusCreated, ethtxtypes.MonitoredTxStatusSent: - return WIPStatus, nil + return WIPClaimStatus, nil case ethtxtypes.MonitoredTxStatusFailed: return FailedClaimStatus, nil case ethtxtypes.MonitoredTxStatusMined, diff --git a/claimsponsor/migrations/claimsponsor0001.sql b/claimsponsor/migrations/claimsponsor0001.sql new file mode 100644 index 00000000..905703a7 --- /dev/null +++ b/claimsponsor/migrations/claimsponsor0001.sql @@ -0,0 +1,20 @@ +-- +migrate Down +DROP TABLE IF EXISTS claim; + +-- +migrate Up +CREATE TABLE claim ( + leaf_type INT NOT NULL, + proof_local_exit_root VARCHAR NOT NULL, + proof_rollup_exit_root VARCHAR NOT NULL, + global_index VARCHAR NOT NULL, + mainnet_exit_root VARCHAR NOT NULL, + rollup_exit_root VARCHAR NOT NULL, + origin_network INT NOT NULL, + origin_token_address VARCHAR NOT NULL, + destination_network INT NOT NULL, + destination_address VARCHAR NOT NULL, + amount VARCHAR NOT NULL, + metadata VARCHAR NOT NULL, + status VARCHAR NOT NULL, + tx_id VARCHAR NOT NULL +); \ No newline at end of file diff --git a/claimsponsor/migrations/migrations.go b/claimsponsor/migrations/migrations.go new file mode 100644 index 00000000..9680746c --- /dev/null +++ b/claimsponsor/migrations/migrations.go @@ -0,0 +1,23 @@ +package migrations + +import ( + _ "embed" + + "github.com/0xPolygon/cdk/db" + "github.com/0xPolygon/cdk/db/types" + treeMigrations "github.com/0xPolygon/cdk/tree/migrations" +) + +//go:embed claimsponsor0001.sql +var mig001 string + +func RunMigrations(dbPath string) error { + migrations := []types.Migration{ + { + ID: "claimsponsor0001", + SQL: mig001, + }, + } + migrations = append(migrations, treeMigrations.Migrations...) + return db.RunMigrations(dbPath, migrations) +} diff --git a/rpc/bridge.go b/rpc/bridge.go index 96394a4f..10c5d2ba 100644 --- a/rpc/bridge.go +++ b/rpc/bridge.go @@ -229,7 +229,7 @@ func (b *BridgeEndpoints) SponsorClaim(claim claimsponsor.Claim) (interface{}, r fmt.Sprintf("this client only sponsors claims for network %d", b.networkID), ) } - if err := b.sponsor.AddClaimToQueue(ctx, &claim); err != nil { + if err := b.sponsor.AddClaimToQueue(&claim); err != nil { return zeroHex, rpc.NewRPCError(rpc.DefaultErrorCode, fmt.Sprintf("error adding claim to the queue %s", err)) } return nil, nil @@ -250,7 +250,7 @@ func (b *BridgeEndpoints) GetSponsoredClaimStatus(globalIndex *big.Int) (interfa if b.sponsor == nil { return zeroHex, rpc.NewRPCError(rpc.DefaultErrorCode, "this client does not support claim sponsoring") } - claim, err := b.sponsor.GetClaim(ctx, globalIndex) + claim, err := b.sponsor.GetClaim(globalIndex) if err != nil { return zeroHex, rpc.NewRPCError(rpc.DefaultErrorCode, fmt.Sprintf("failed to get claim status, error: %s", err)) } diff --git a/rpc/bridge_interfaces.go b/rpc/bridge_interfaces.go index 84292e22..ece5acfb 100644 --- a/rpc/bridge_interfaces.go +++ b/rpc/bridge_interfaces.go @@ -35,6 +35,6 @@ type L1InfoTreer interface { } type ClaimSponsorer interface { - AddClaimToQueue(ctx context.Context, claim *claimsponsor.Claim) error - GetClaim(ctx context.Context, globalIndex *big.Int) (*claimsponsor.Claim, error) + AddClaimToQueue(claim *claimsponsor.Claim) error + GetClaim(globalIndex *big.Int) (*claimsponsor.Claim, error) } diff --git a/rpc/mocks/claim_sponsorer.go b/rpc/mocks/claim_sponsorer.go index 59530955..9a9ef9b5 100644 --- a/rpc/mocks/claim_sponsorer.go +++ b/rpc/mocks/claim_sponsorer.go @@ -3,11 +3,9 @@ package mocks import ( - context "context" big "math/big" claimsponsor "github.com/0xPolygon/cdk/claimsponsor" - mock "github.com/stretchr/testify/mock" ) @@ -24,17 +22,17 @@ func (_m *ClaimSponsorer) EXPECT() *ClaimSponsorer_Expecter { return &ClaimSponsorer_Expecter{mock: &_m.Mock} } -// AddClaimToQueue provides a mock function with given fields: ctx, claim -func (_m *ClaimSponsorer) AddClaimToQueue(ctx context.Context, claim *claimsponsor.Claim) error { - ret := _m.Called(ctx, claim) +// AddClaimToQueue provides a mock function with given fields: claim +func (_m *ClaimSponsorer) AddClaimToQueue(claim *claimsponsor.Claim) error { + ret := _m.Called(claim) if len(ret) == 0 { panic("no return value specified for AddClaimToQueue") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *claimsponsor.Claim) error); ok { - r0 = rf(ctx, claim) + if rf, ok := ret.Get(0).(func(*claimsponsor.Claim) error); ok { + r0 = rf(claim) } else { r0 = ret.Error(0) } @@ -48,15 +46,14 @@ type ClaimSponsorer_AddClaimToQueue_Call struct { } // AddClaimToQueue is a helper method to define mock.On call -// - ctx context.Context // - claim *claimsponsor.Claim -func (_e *ClaimSponsorer_Expecter) AddClaimToQueue(ctx interface{}, claim interface{}) *ClaimSponsorer_AddClaimToQueue_Call { - return &ClaimSponsorer_AddClaimToQueue_Call{Call: _e.mock.On("AddClaimToQueue", ctx, claim)} +func (_e *ClaimSponsorer_Expecter) AddClaimToQueue(claim interface{}) *ClaimSponsorer_AddClaimToQueue_Call { + return &ClaimSponsorer_AddClaimToQueue_Call{Call: _e.mock.On("AddClaimToQueue", claim)} } -func (_c *ClaimSponsorer_AddClaimToQueue_Call) Run(run func(ctx context.Context, claim *claimsponsor.Claim)) *ClaimSponsorer_AddClaimToQueue_Call { +func (_c *ClaimSponsorer_AddClaimToQueue_Call) Run(run func(claim *claimsponsor.Claim)) *ClaimSponsorer_AddClaimToQueue_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*claimsponsor.Claim)) + run(args[0].(*claimsponsor.Claim)) }) return _c } @@ -66,14 +63,14 @@ func (_c *ClaimSponsorer_AddClaimToQueue_Call) Return(_a0 error) *ClaimSponsorer return _c } -func (_c *ClaimSponsorer_AddClaimToQueue_Call) RunAndReturn(run func(context.Context, *claimsponsor.Claim) error) *ClaimSponsorer_AddClaimToQueue_Call { +func (_c *ClaimSponsorer_AddClaimToQueue_Call) RunAndReturn(run func(*claimsponsor.Claim) error) *ClaimSponsorer_AddClaimToQueue_Call { _c.Call.Return(run) return _c } -// GetClaim provides a mock function with given fields: ctx, globalIndex -func (_m *ClaimSponsorer) GetClaim(ctx context.Context, globalIndex *big.Int) (*claimsponsor.Claim, error) { - ret := _m.Called(ctx, globalIndex) +// GetClaim provides a mock function with given fields: globalIndex +func (_m *ClaimSponsorer) GetClaim(globalIndex *big.Int) (*claimsponsor.Claim, error) { + ret := _m.Called(globalIndex) if len(ret) == 0 { panic("no return value specified for GetClaim") @@ -81,19 +78,19 @@ func (_m *ClaimSponsorer) GetClaim(ctx context.Context, globalIndex *big.Int) (* var r0 *claimsponsor.Claim var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*claimsponsor.Claim, error)); ok { - return rf(ctx, globalIndex) + if rf, ok := ret.Get(0).(func(*big.Int) (*claimsponsor.Claim, error)); ok { + return rf(globalIndex) } - if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *claimsponsor.Claim); ok { - r0 = rf(ctx, globalIndex) + if rf, ok := ret.Get(0).(func(*big.Int) *claimsponsor.Claim); ok { + r0 = rf(globalIndex) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*claimsponsor.Claim) } } - if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { - r1 = rf(ctx, globalIndex) + if rf, ok := ret.Get(1).(func(*big.Int) error); ok { + r1 = rf(globalIndex) } else { r1 = ret.Error(1) } @@ -107,15 +104,14 @@ type ClaimSponsorer_GetClaim_Call struct { } // GetClaim is a helper method to define mock.On call -// - ctx context.Context // - globalIndex *big.Int -func (_e *ClaimSponsorer_Expecter) GetClaim(ctx interface{}, globalIndex interface{}) *ClaimSponsorer_GetClaim_Call { - return &ClaimSponsorer_GetClaim_Call{Call: _e.mock.On("GetClaim", ctx, globalIndex)} +func (_e *ClaimSponsorer_Expecter) GetClaim(globalIndex interface{}) *ClaimSponsorer_GetClaim_Call { + return &ClaimSponsorer_GetClaim_Call{Call: _e.mock.On("GetClaim", globalIndex)} } -func (_c *ClaimSponsorer_GetClaim_Call) Run(run func(ctx context.Context, globalIndex *big.Int)) *ClaimSponsorer_GetClaim_Call { +func (_c *ClaimSponsorer_GetClaim_Call) Run(run func(globalIndex *big.Int)) *ClaimSponsorer_GetClaim_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*big.Int)) + run(args[0].(*big.Int)) }) return _c } @@ -125,7 +121,7 @@ func (_c *ClaimSponsorer_GetClaim_Call) Return(_a0 *claimsponsor.Claim, _a1 erro return _c } -func (_c *ClaimSponsorer_GetClaim_Call) RunAndReturn(run func(context.Context, *big.Int) (*claimsponsor.Claim, error)) *ClaimSponsorer_GetClaim_Call { +func (_c *ClaimSponsorer_GetClaim_Call) RunAndReturn(run func(*big.Int) (*claimsponsor.Claim, error)) *ClaimSponsorer_GetClaim_Call { _c.Call.Return(run) return _c }