Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Cover all rpc.go file with UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Dec 1, 2023
1 parent 3eff1a9 commit b1d7af7
Show file tree
Hide file tree
Showing 3 changed files with 348 additions and 88 deletions.
4 changes: 4 additions & 0 deletions rpc/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ type EthTxManager interface {
type ZkEVMClientInterface interface {
BatchByNumber(ctx context.Context, number *big.Int) (*types.Batch, error)
}

type ZkEVMClientClientCreator interface {
NewClient(rpc string) ZkEVMClientInterface
}
32 changes: 21 additions & 11 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ const (

type FullNodeRPCs map[common.Address]string

var _ ZkEVMClientClientCreator = (*zkEVMClientCreator)(nil)

type zkEVMClientCreator struct{}

func (zc *zkEVMClientCreator) NewClient(rpc string) ZkEVMClientInterface {
return client.NewClient(rpc)
}

// InteropEndpoints contains implementations for the "interop" RPC endpoints
type InteropEndpoints struct {
db DBInterface
etherman EthermanInterface
interopAdminAddr common.Address
fullNodeRPCs FullNodeRPCs
ethTxManager EthTxManager
db DBInterface
etherman EthermanInterface
interopAdminAddr common.Address
fullNodeRPCs FullNodeRPCs
ethTxManager EthTxManager
zkEVMClientCreator ZkEVMClientClientCreator
}

// NewInteropEndpoints returns InteropEndpoints
Expand All @@ -39,11 +48,12 @@ func NewInteropEndpoints(
ethTxManager EthTxManager,
) *InteropEndpoints {
return &InteropEndpoints{
db: db,
interopAdminAddr: interopAdminAddr,
etherman: etherman,
fullNodeRPCs: fullNodeRPCs,
ethTxManager: ethTxManager,
db: db,
interopAdminAddr: interopAdminAddr,
etherman: etherman,
fullNodeRPCs: fullNodeRPCs,
ethTxManager: ethTxManager,
zkEVMClientCreator: &zkEVMClientCreator{},
}
}

Expand Down Expand Up @@ -92,7 +102,7 @@ func (i *InteropEndpoints) SendTx(signedTx tx.SignedTx) (interface{}, types.Erro
// Check expected root vs root from the managed full node
// TODO: go stateless, depends on https://github.com/0xPolygonHermez/zkevm-prover/issues/581
// when this happens we should go async from here, since processing all the batches could take a lot of time
zkEVMClient := client.NewClient(i.fullNodeRPCs[signedTx.Tx.L1Contract])
zkEVMClient := i.zkEVMClientCreator.NewClient(i.fullNodeRPCs[signedTx.Tx.L1Contract])
batch, err := zkEVMClient.BatchByNumber(
ctx,
big.NewInt(int64(signedTx.Tx.NewVerifiedBatch)),
Expand Down
Loading

0 comments on commit b1d7af7

Please sign in to comment.