-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24d05c4
commit 5fe2674
Showing
11 changed files
with
341 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
core/services/ocr2/plugins/ccip/estimatorconfig/interceptors/mantle/interceptor_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package mantle | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestInterceptor(t *testing.T) { | ||
ethClient := mocks.NewClient(t) | ||
ctx := context.Background() | ||
|
||
tokenRatio := big.NewInt(10) | ||
interceptor := NewInterceptor(ctx, ethClient) | ||
|
||
ethClient.On("CallContract", ctx, mock.IsType(ethereum.CallMsg{}), mock.IsType(&big.Int{})). | ||
Return(common.BigToHash(tokenRatio).Bytes(), nil) | ||
|
||
modExecGasPrice, modDAGasPrice, err := interceptor.ModifyGasPriceComponents(ctx, big.NewInt(1), big.NewInt(1)) | ||
require.NoError(t, err) | ||
require.Equal(t, modExecGasPrice.Int64(), int64(20)) | ||
require.Equal(t, modDAGasPrice.Int64(), int64(1)) | ||
|
||
// second call won't invoke eth client | ||
modExecGasPrice, modDAGasPrice, err = interceptor.ModifyGasPriceComponents(ctx, big.NewInt(2), big.NewInt(1)) | ||
require.NoError(t, err) | ||
require.Equal(t, modExecGasPrice.Int64(), int64(30)) | ||
require.Equal(t, modDAGasPrice.Int64(), int64(1)) | ||
} | ||
|
||
func TestModifyGasPriceComponents(t *testing.T) { | ||
testCases := map[string]struct { | ||
execGasPrice *big.Int | ||
daGasPrice *big.Int | ||
tokenRatio *big.Int | ||
resultExecGasPrice *big.Int | ||
}{ | ||
"regular": { | ||
execGasPrice: big.NewInt(1), | ||
daGasPrice: big.NewInt(1), | ||
tokenRatio: big.NewInt(10), | ||
resultExecGasPrice: big.NewInt(20), | ||
}, | ||
"zero DAGasPrice": { | ||
execGasPrice: big.NewInt(1), | ||
daGasPrice: big.NewInt(0), | ||
tokenRatio: big.NewInt(1), | ||
resultExecGasPrice: big.NewInt(1), | ||
}, | ||
"zero token ratio": { | ||
execGasPrice: big.NewInt(15), | ||
daGasPrice: big.NewInt(10), | ||
tokenRatio: big.NewInt(0), | ||
resultExecGasPrice: big.NewInt(0), | ||
}, | ||
} | ||
|
||
for tcName, tc := range testCases { | ||
t.Run(tcName, func(t *testing.T) { | ||
ethClient := mocks.NewClient(t) | ||
ctx := context.Background() | ||
|
||
interceptor := NewInterceptor(ctx, ethClient) | ||
|
||
ethClient.On("CallContract", ctx, mock.IsType(ethereum.CallMsg{}), mock.IsType(&big.Int{})). | ||
Return(common.BigToHash(tc.tokenRatio).Bytes(), nil) | ||
|
||
modExecGasPrice, modDAGasPrice, err := interceptor.ModifyGasPriceComponents(ctx, tc.execGasPrice, tc.daGasPrice) | ||
require.NoError(t, err) | ||
require.Equal(t, modExecGasPrice, tc.resultExecGasPrice) | ||
require.Equal(t, modDAGasPrice, tc.daGasPrice) | ||
}) | ||
} | ||
} |
Oops, something went wrong.