Skip to content

Commit

Permalink
add test for AddNewSymbolToBandOracleRequest oracle module
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Nov 13, 2024
1 parent 4ccb6c3 commit a3c88d1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
49 changes: 47 additions & 2 deletions x/oracle/keeper/band_oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
12 changes: 10 additions & 2 deletions x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

func (s *KeeperTestSuite) SetupTest() {
s.Setup()
s.k = s.App.OracleKeeper
}

0 comments on commit a3c88d1

Please sign in to comment.