Skip to content

Commit

Permalink
Fixing price getter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Oct 23, 2024
1 parent 486d78a commit ba6ec4e
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions core/services/ocr2/plugins/ccip/internal/pricegetter/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ func testParamAggregatorOnly(t *testing.T) testParameters {
AnsweredInRound: big.NewInt(4000),
}
contractReaders := map[uint64]types.ContractReader{
uint64(101): mockCR(t, []uint8{8}, cfg, TK1, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, TK2, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(103): mockCR(t, []uint8{18}, cfg, TK3, []aggregator_v3_interface.LatestRoundData{round3}),
uint64(104): mockCR(t, []uint8{20}, cfg, TK4, []aggregator_v3_interface.LatestRoundData{round4}),
uint64(101): mockCR(t, []uint8{8}, cfg, []common.Address{TK1}, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, []common.Address{TK2}, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(103): mockCR(t, []uint8{18}, cfg, []common.Address{TK3}, []aggregator_v3_interface.LatestRoundData{round3}),
uint64(104): mockCR(t, []uint8{20}, cfg, []common.Address{TK4}, []aggregator_v3_interface.LatestRoundData{round4}),
}
expectedTokenPrices := map[common.Address]big.Int{
TK1: *multExp(round1.Answer, 10), // expected in 1e18 format.
Expand Down Expand Up @@ -261,8 +261,8 @@ func testParamAggregatorOnlyMulti(t *testing.T) testParameters {
AnsweredInRound: big.NewInt(3000),
}
contractReaders := map[uint64]types.ContractReader{
uint64(101): mockCR(t, []uint8{8}, cfg, TK1, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8, 8}, cfg, TK2, []aggregator_v3_interface.LatestRoundData{round2, round3}),
uint64(101): mockCR(t, []uint8{8}, cfg, []common.Address{TK1}, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8, 8}, cfg, []common.Address{TK2, TK3}, []aggregator_v3_interface.LatestRoundData{round2, round3}),
}
expectedTokenPrices := map[common.Address]big.Int{
TK1: *multExp(round1.Answer, 10),
Expand Down Expand Up @@ -347,8 +347,8 @@ func testParamNoAggregatorForToken(t *testing.T) testParameters {
AnsweredInRound: big.NewInt(2000),
}
contractReaders := map[uint64]types.ContractReader{
uint64(101): mockCR(t, []uint8{8}, cfg, TK1, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, TK2, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(101): mockCR(t, []uint8{8}, cfg, []common.Address{TK1}, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, []common.Address{TK2}, []aggregator_v3_interface.LatestRoundData{round2}),
}
expectedTokenPrices := map[common.Address]big.Int{
TK1: *round1.Answer,
Expand Down Expand Up @@ -401,8 +401,8 @@ func testParamAggregatorAndStaticValid(t *testing.T) testParameters {
AnsweredInRound: big.NewInt(2000),
}
contractReaders := map[uint64]types.ContractReader{
uint64(101): mockCR(t, []uint8{8}, cfg, TK1, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, TK2, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(101): mockCR(t, []uint8{8}, cfg, []common.Address{TK1}, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, []common.Address{TK2}, []aggregator_v3_interface.LatestRoundData{round2}),
}
expectedTokenPrices := map[common.Address]big.Int{
TK1: *multExp(round1.Answer, 10),
Expand Down Expand Up @@ -464,9 +464,9 @@ func testParamAggregatorAndStaticTokenCollision(t *testing.T) testParameters {
AnsweredInRound: big.NewInt(3000),
}
contractReaders := map[uint64]types.ContractReader{
uint64(101): mockCR(t, []uint8{8}, cfg, TK1, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, TK2, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(103): mockCR(t, []uint8{8}, cfg, TK3, []aggregator_v3_interface.LatestRoundData{round3}),
uint64(101): mockCR(t, []uint8{8}, cfg, []common.Address{TK1}, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, []common.Address{TK2}, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(103): mockCR(t, []uint8{8}, cfg, []common.Address{TK3}, []aggregator_v3_interface.LatestRoundData{round3}),
}
return testParameters{
cfg: cfg,
Expand Down Expand Up @@ -504,7 +504,7 @@ func testParamBatchCallReturnsErr(t *testing.T) testParameters {
AnsweredInRound: big.NewInt(1000),
}
contractReaders := map[uint64]types.ContractReader{
uint64(101): mockCR(t, []uint8{8}, cfg, TK1, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(101): mockCR(t, []uint8{8}, cfg, []common.Address{TK1}, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockErrCR(t),
}
return testParameters{
Expand Down Expand Up @@ -563,9 +563,9 @@ func testLessInputsThanDefinedPrices(t *testing.T) testParameters {
AnsweredInRound: big.NewInt(3000),
}
contractReaders := map[uint64]types.ContractReader{
uint64(101): mockCR(t, []uint8{8}, cfg, TK1, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, TK2, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(103): mockCR(t, []uint8{8}, cfg, TK3, []aggregator_v3_interface.LatestRoundData{round3}),
uint64(101): mockCR(t, []uint8{8}, cfg, []common.Address{TK1}, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, []common.Address{TK2}, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(103): mockCR(t, []uint8{8}, cfg, []common.Address{TK3}, []aggregator_v3_interface.LatestRoundData{round3}),
}
expectedTokenPrices := map[common.Address]big.Int{
TK1: *multExp(round1.Answer, 10),
Expand Down Expand Up @@ -628,9 +628,9 @@ func testGetAllTokensAggregatorAndStatic(t *testing.T) testParameters {
AnsweredInRound: big.NewInt(3000),
}
contractReaders := map[uint64]types.ContractReader{
uint64(101): mockCR(t, []uint8{8}, cfg, TK1, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, TK2, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(103): mockCR(t, []uint8{8}, cfg, TK3, []aggregator_v3_interface.LatestRoundData{round3}),
uint64(101): mockCR(t, []uint8{8}, cfg, []common.Address{TK1}, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, []common.Address{TK2}, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(103): mockCR(t, []uint8{8}, cfg, []common.Address{TK3}, []aggregator_v3_interface.LatestRoundData{round3}),
}
expectedTokenPricesForAll := map[common.Address]big.Int{
TK1: *multExp(round1.Answer, 10),
Expand Down Expand Up @@ -688,9 +688,9 @@ func testGetAllTokensAggregatorOnly(t *testing.T) testParameters {
AnsweredInRound: big.NewInt(3000),
}
contractReaders := map[uint64]types.ContractReader{
uint64(101): mockCR(t, []uint8{8}, cfg, TK1, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, TK2, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(103): mockCR(t, []uint8{8}, cfg, TK3, []aggregator_v3_interface.LatestRoundData{round3}),
uint64(101): mockCR(t, []uint8{8}, cfg, []common.Address{TK1}, []aggregator_v3_interface.LatestRoundData{round1}),
uint64(102): mockCR(t, []uint8{8}, cfg, []common.Address{TK2}, []aggregator_v3_interface.LatestRoundData{round2}),
uint64(103): mockCR(t, []uint8{8}, cfg, []common.Address{TK3}, []aggregator_v3_interface.LatestRoundData{round3}),
}

expectedTokenPricesForAll := map[common.Address]big.Int{
Expand Down Expand Up @@ -737,17 +737,15 @@ func testGetAllTokensStaticOnly(t *testing.T) testParameters {
}
}

func mockCR(t *testing.T, decimals []uint8, cfg config.DynamicPriceGetterConfig, addr common.Address, rounds []aggregator_v3_interface.LatestRoundData) *mocks.ContractReader {
func mockCR(t *testing.T, decimals []uint8, cfg config.DynamicPriceGetterConfig, addr []common.Address, rounds []aggregator_v3_interface.LatestRoundData) *mocks.ContractReader {
caller := mocks.NewContractReader(t)

contractAddress := cfg.AggregatorPrices[addr].AggregatorContractAddress.Hex()

// Mock batch calls per chain: all decimals calls then all latestRoundData calls.
bGLVR := make(types.BatchGetLatestValuesResult)

for i := range len(decimals) {
boundContract := types.BoundContract{
Address: contractAddress,
Address: cfg.AggregatorPrices[addr[i]].AggregatorContractAddress.Hex(),
Name: fmt.Sprintf("%v_%v", OffchainAggregator, i),
}
bGLVR[boundContract] = types.ContractBatchResults{}
Expand All @@ -759,7 +757,7 @@ func mockCR(t *testing.T, decimals []uint8, cfg config.DynamicPriceGetterConfig,
}
readRes.SetResult(&d, nil)
boundContract := types.BoundContract{
Address: contractAddress,
Address: cfg.AggregatorPrices[addr[i]].AggregatorContractAddress.Hex(),
Name: contractName,
}
bGLVR[boundContract] = append(bGLVR[boundContract], readRes)
Expand All @@ -772,7 +770,7 @@ func mockCR(t *testing.T, decimals []uint8, cfg config.DynamicPriceGetterConfig,
}
readRes.SetResult(&r, nil)
boundContract := types.BoundContract{
Address: contractAddress,
Address: cfg.AggregatorPrices[addr[i]].AggregatorContractAddress.Hex(),
Name: contractName,
}
bGLVR[boundContract] = append(bGLVR[boundContract], readRes)
Expand Down

0 comments on commit ba6ec4e

Please sign in to comment.