From a3c88d11e5917da81b55776917714487e7cf6447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDongLieu=E2=80=9D?= Date: Wed, 13 Nov 2024 11:13:21 +0700 Subject: [PATCH] add test for AddNewSymbolToBandOracleRequest oracle module --- x/oracle/keeper/band_oracle_test.go | 49 +++++++++++++++++++++++++++-- x/oracle/keeper/keeper_test.go | 12 +++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/x/oracle/keeper/band_oracle_test.go b/x/oracle/keeper/band_oracle_test.go index b6dcdcc..0da0fef 100644 --- a/x/oracle/keeper/band_oracle_test.go +++ b/x/oracle/keeper/band_oracle_test.go @@ -362,8 +362,8 @@ func TestProcessBandOraclePrices(t *testing.T) { }, oracleOutput: types.BandOutput{ Responses: []types.Response{ - {Symbol: "ATOM", ResponseCode: 0, Rate: 100 * types.BandPriceMultiplier}, - {Symbol: "BTC", ResponseCode: 0, Rate: 50000 * types.BandPriceMultiplier}, + {Symbol: "ATOM", ResponseCode: 0, Rate: 100 * types.BandPriceMultiplier}, + {Symbol: "BTC", ResponseCode: 0, Rate: 50000 * types.BandPriceMultiplier}, }, }, expectedError: false, @@ -421,3 +421,48 @@ func TestProcessBandOraclePrices(t *testing.T) { }) } } + +func (s *KeeperTestSuite) TestParams() { + s.SetupTest() + var ( + symbolScript = map[int64][]string{ + 42: {"ATOM", "OSMO"}, + 52: {"USD", "EUR", "JPY"}, + } + ) + + // 42-1.ATOM + err := s.k.AddNewSymbolToBandOracleRequest(s.Ctx, symbolScript[42][0], 42) + s.Require().NoError(err) + // 42-2.OSMO + err = s.k.AddNewSymbolToBandOracleRequest(s.Ctx, symbolScript[42][1], 42) + s.Require().NoError(err) + + // 42-1.ATOM duplicate test + err = s.k.AddNewSymbolToBandOracleRequest(s.Ctx, symbolScript[42][0], 42) + s.Require().NoError(err) + + // 52-1.USD + err = s.k.AddNewSymbolToBandOracleRequest(s.Ctx, symbolScript[52][0], 52) + s.Require().NoError(err) + + // 52-2.EUR + err = s.k.AddNewSymbolToBandOracleRequest(s.Ctx, symbolScript[52][1], 52) + s.Require().NoError(err) + + // 52-3.JPY + err = s.k.AddNewSymbolToBandOracleRequest(s.Ctx, symbolScript[52][2], 52) + s.Require().NoError(err) + + // 52-1.USD duplicate test + err = s.k.AddNewSymbolToBandOracleRequest(s.Ctx, symbolScript[52][0], 52) + s.Require().NoError(err) + + err = s.k.IteratorOracleRequests(s.Ctx, func(bandOracleRequest types.BandOracleRequest) bool { + expSymbols, ok := symbolScript[bandOracleRequest.OracleScriptId] + s.Require().True(ok) + s.Require().Equal(len(expSymbols), len(bandOracleRequest.Symbols)) + return false + }) + s.Require().NoError(err) +} diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index 0148e6e..2ce7edb 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -2,14 +2,22 @@ package keeper_test import ( "testing" - testifysuite "github.com/stretchr/testify/suite" + apptesting "github.com/onomyprotocol/reserve/app/apptesting" + "github.com/onomyprotocol/reserve/x/oracle/keeper" + testifysuite "github.com/stretchr/testify/suite" ) type KeeperTestSuite struct { apptesting.KeeperTestHelper + k keeper.Keeper } func TestKeeperTestSuite(t *testing.T) { testifysuite.Run(t, new(KeeperTestSuite)) -} \ No newline at end of file +} + +func (s *KeeperTestSuite) SetupTest() { + s.Setup() + s.k = s.App.OracleKeeper +}