Skip to content

Commit

Permalink
♻️ Fix test and mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
ishantiw committed Jan 18, 2024
1 parent d614860 commit 9c989ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 3 additions & 2 deletions pkg/chain/chain_mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/stretchr/testify/mock"
)

// Mock function
type MockAPIClient struct {
mock.Mock
}
Expand Down Expand Up @@ -40,7 +39,9 @@ type MockRPCClient struct {
}

func (c *MockRPCClient) Call(result interface{}, method string, args ...interface{}) error {
ret := c.Called()
allArgs := []interface{}{result, method}
allArgs = append(allArgs, args...)
ret := c.Called(allArgs...)

ptr := &result
*ptr = ret.Get(0)
Expand Down
12 changes: 5 additions & 7 deletions pkg/chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/assert"
)

const (
fake_url = "localhost:8080"
"github.com/stretchr/testify/mock"
)

func TestNewChainAPIClient(t *testing.T) {
Expand Down Expand Up @@ -85,9 +82,10 @@ func TestGetProof(t *testing.T) {
var proofResponseExpected ProofResponse

apiClientMock.On("Client").Return(rpcClientMock, nil)
rpcClientMock.On("Call", &proofResponseExpected, RPCEndpointGetProof, address.String(), []string{}, blockNumber).Return(fmt.Println("Error"))
rpcClientMock.On("Call", mock.AnythingOfType("*chain.ProofResponse"), RPCEndpointGetProof, address.String(), []string{}, blockNumber).Return(fmt.Println("Error"))

proofResponseRecieved, _ := chainClient.GetProof(rpcClientMock, blockNumber, address.Hex())
proofResponseRecieved, err := chainClient.GetProof(rpcClientMock, blockNumber, address.Hex())

assert.Equal(t, proofResponseExpected, proofResponseRecieved)
assert.NoError(t, err)
assert.Equal(t, &proofResponseExpected, proofResponseRecieved)
}

0 comments on commit 9c989ff

Please sign in to comment.