From e3a15cda0edb674cef8fd1a85fca349d02887e7e Mon Sep 17 00:00:00 2001 From: Kitipong Sirirueangsakul Date: Tue, 3 Dec 2024 03:14:17 +0700 Subject: [PATCH 1/2] use default timestamp from blocktime instead of 0, cleanup test --- x/feeds/client/cli/tx.go | 2 +- x/feeds/keeper/grpc_query_test.go | 6 ++ x/tunnel/client/cli/util_test.go | 4 +- x/tunnel/ibc_module_test.go | 7 +- x/tunnel/keeper/helper.go | 3 +- x/tunnel/keeper/helper_test.go | 83 ++++++++++++++++---- x/tunnel/keeper/keeper_latest_prices_test.go | 21 ++++- x/tunnel/keeper/keeper_packet.go | 8 +- x/tunnel/keeper/keeper_packet_test.go | 27 ++++--- x/tunnel/keeper/keeper_test.go | 2 +- x/tunnel/keeper/keeper_tunnel_test.go | 20 ++--- x/tunnel/keeper/msg_server_test.go | 27 ++++--- x/tunnel/types/encoding_tss_test.go | 8 +- x/tunnel/types/latest_prices_test.go | 6 +- x/tunnel/types/route_ibc_test.go | 6 +- 15 files changed, 165 insertions(+), 65 deletions(-) diff --git a/x/feeds/client/cli/tx.go b/x/feeds/client/cli/tx.go index 007e5ba61..0a3f3a6c4 100644 --- a/x/feeds/client/cli/tx.go +++ b/x/feeds/client/cli/tx.go @@ -146,7 +146,7 @@ func GetTxCmdVote() *cobra.Command { fmt.Sprintf( `Vote signal ids and their power. Example: -$ %s tx feeds vote BTC,1000000 --from mykey +$ %s tx feeds vote CS:BAND-USD,1000000 --from mykey `, version.AppName, ), diff --git a/x/feeds/keeper/grpc_query_test.go b/x/feeds/keeper/grpc_query_test.go index 5a47e6b2c..7c017aec4 100644 --- a/x/feeds/keeper/grpc_query_test.go +++ b/x/feeds/keeper/grpc_query_test.go @@ -80,16 +80,19 @@ func (suite *KeeperTestSuite) TestQueryPrices() { // Setup multiple prices prices := []types.Price{ { + Status: types.PRICE_STATUS_AVAILABLE, SignalID: "CS:BAND-USD", Price: 100000000, Timestamp: 1234567890, }, { + Status: types.PRICE_STATUS_AVAILABLE, SignalID: "CS:ATOM-USD", Price: 200000000, Timestamp: 1234567890, }, { + Status: types.PRICE_STATUS_AVAILABLE, SignalID: "CS:BTC-USD", Price: 300000000, Timestamp: 1234567890, @@ -173,16 +176,19 @@ func (suite *KeeperTestSuite) TestQueryAllPrices() { // Setup multiple prices prices := []types.Price{ { + Status: types.PRICE_STATUS_AVAILABLE, SignalID: "CS:ATOM-USD", Price: 200000000, Timestamp: 1234567891, }, { + Status: types.PRICE_STATUS_AVAILABLE, SignalID: "CS:BAND-USD", Price: 100000000, Timestamp: 1234567890, }, { + Status: types.PRICE_STATUS_AVAILABLE, SignalID: "CS:BTC-USD", Price: 300000000, Timestamp: 1234567892, diff --git a/x/tunnel/client/cli/util_test.go b/x/tunnel/client/cli/util_test.go index fa089707c..f6f247af2 100644 --- a/x/tunnel/client/cli/util_test.go +++ b/x/tunnel/client/cli/util_test.go @@ -10,8 +10,8 @@ import ( func TestParseSignalDeviations(t *testing.T) { signalDeviations := []SignalDeviation{ - {SignalID: "BTC", DeviationBPS: 2000}, - {SignalID: "ETH", DeviationBPS: 4000}, + {SignalID: "CS:BTC-USD", DeviationBPS: 2000}, + {SignalID: "CS:ETH-USD", DeviationBPS: 4000}, } file, cleanup := createTempSignalDeviationFile(signalDeviations) defer cleanup() diff --git a/x/tunnel/ibc_module_test.go b/x/tunnel/ibc_module_test.go index 4629de174..0b115d6bf 100644 --- a/x/tunnel/ibc_module_test.go +++ b/x/tunnel/ibc_module_test.go @@ -35,7 +35,12 @@ func TestPacketDataUnmarshalerInterface(t *testing.T) { TunnelID: 1, Sequence: 1, Prices: []feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_NOT_IN_CURRENT_FEEDS, SignalID: "BTC", Price: 50000}, + { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:BAND-USD", + Price: 50000, + Timestamp: 1733000000, + }, }, CreatedAt: 1633024800, } diff --git a/x/tunnel/keeper/helper.go b/x/tunnel/keeper/helper.go index 79e239939..204e03f93 100644 --- a/x/tunnel/keeper/helper.go +++ b/x/tunnel/keeper/helper.go @@ -23,6 +23,7 @@ func GenerateNewPrices( signalDeviations []types.SignalDeviation, latestPricesMap map[string]feedstypes.Price, feedsPricesMap map[string]feedstypes.Price, + timestamp int64, sendAll bool, ) []feedstypes.Price { shouldSend := false @@ -36,7 +37,7 @@ func GenerateNewPrices( feedPrice, ok := feedsPricesMap[sd.SignalID] if !ok { - feedPrice = feedstypes.NewPrice(feedstypes.PRICE_STATUS_NOT_IN_CURRENT_FEEDS, sd.SignalID, 0, 0) + feedPrice = feedstypes.NewPrice(feedstypes.PRICE_STATUS_NOT_IN_CURRENT_FEEDS, sd.SignalID, 0, timestamp) } // calculate deviation between old price and new price and compare with the threshold. diff --git a/x/tunnel/keeper/helper_test.go b/x/tunnel/keeper/helper_test.go index a3174d1ec..af53c314c 100644 --- a/x/tunnel/keeper/helper_test.go +++ b/x/tunnel/keeper/helper_test.go @@ -11,17 +11,27 @@ func (s *KeeperTestSuite) TestGeneratePricesSendAll() { tunnelID := uint64(1) pricesMap := map[string]feedstypes.Price{ - "BTC/USD": {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC/USD", Price: 50000, Timestamp: 0}, + "CS:BAND-USD": { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:BAND-USD", + Price: 50000, + Timestamp: 1733000000, + }, } sendAll := true tunnel := types.Tunnel{ ID: tunnelID, SignalDeviations: []types.SignalDeviation{ - {SignalID: "BTC/USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, + {SignalID: "CS:BAND-USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, }, } latestPrices := types.NewLatestPrices(tunnelID, []feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_NOT_IN_CURRENT_FEEDS, SignalID: "BTC/USD", Price: 0}, + { + Status: feedstypes.PRICE_STATUS_NOT_IN_CURRENT_FEEDS, + SignalID: "CS:BAND-USD", + Price: 0, + Timestamp: 1733000000, + }, }, 0) latestPricesMap := keeper.CreatePricesMap(latestPrices.Prices) @@ -33,6 +43,7 @@ func (s *KeeperTestSuite) TestGeneratePricesSendAll() { tunnel.SignalDeviations, latestPricesMap, pricesMap, + 1733000000, sendAll, ) s.Require().Len(newPrices, 1) @@ -43,20 +54,40 @@ func (s *KeeperTestSuite) TestGeneratePricesMeetHardDeviation() { tunnelID := uint64(1) pricesMap := map[string]feedstypes.Price{ - "BTC/USD": {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC/USD", Price: 50000, Timestamp: 0}, - "ETH/USD": {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC/USD", Price: 2000, Timestamp: 0}, + "CS:BAND-USD": { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:BAND-USD", + Price: 50000, + Timestamp: 1733000000, + }, + "CS:ETH-USD": { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:ETH-USD", + Price: 2000, + Timestamp: 1733000000, + }, } sendAll := false tunnel := types.Tunnel{ ID: tunnelID, SignalDeviations: []types.SignalDeviation{ - {SignalID: "BTC/USD", SoftDeviationBPS: 100, HardDeviationBPS: 300}, - {SignalID: "ETH/USD", SoftDeviationBPS: 100, HardDeviationBPS: 300}, + {SignalID: "CS:BAND-USD", SoftDeviationBPS: 100, HardDeviationBPS: 300}, + {SignalID: "CS:ETH-USD", SoftDeviationBPS: 100, HardDeviationBPS: 300}, }, } latestPrices := types.NewLatestPrices(tunnelID, []feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC/USD", Price: 48500}, // 3% - {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "ETH/USD", Price: 1980}, // 1% + { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:BAND-USD", + Price: 48500, + Timestamp: 1732000000, + }, // 3% + { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:ETH-USD", + Price: 1980, + Timestamp: 1732000000, + }, // 1% }, 0) latestPricesMap := keeper.CreatePricesMap(latestPrices.Prices) @@ -67,6 +98,7 @@ func (s *KeeperTestSuite) TestGeneratePricesMeetHardDeviation() { tunnel.SignalDeviations, latestPricesMap, pricesMap, + 1733000000, sendAll, ) s.Require().Len(newPrices, 2) @@ -77,20 +109,40 @@ func (s *KeeperTestSuite) TestGeneratePricesNotMeetHardDeviation() { tunnelID := uint64(1) pricesMap := map[string]feedstypes.Price{ - "BTC/USD": {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC/USD", Price: 50000, Timestamp: 0}, - "ETH/USD": {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC/USD", Price: 2000, Timestamp: 0}, + "CS:BAND-USD": { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:BAND-USD", + Price: 50000, + Timestamp: 1733000000, + }, + "CS:ETH-USD": { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:ETH-USD", + Price: 2000, + Timestamp: 1733000000, + }, } sendAll := false tunnel := types.Tunnel{ ID: tunnelID, SignalDeviations: []types.SignalDeviation{ - {SignalID: "BTC/USD", SoftDeviationBPS: 100, HardDeviationBPS: 300}, - {SignalID: "ETH/USD", SoftDeviationBPS: 100, HardDeviationBPS: 300}, + {SignalID: "CS:BAND-USD", SoftDeviationBPS: 100, HardDeviationBPS: 300}, + {SignalID: "CS:ETH-USD", SoftDeviationBPS: 100, HardDeviationBPS: 300}, }, } latestPrices := types.NewLatestPrices(tunnelID, []feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC/USD", Price: 49000}, // 2% - {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "ETH/USD", Price: 1950}, // 2.5% + { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:BAND-USD", + Price: 49000, + Timestamp: 1732000000, + }, // 2% + { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:ETH-USD", + Price: 1950, + Timestamp: 1732000000, + }, // 2.5% }, 0) latestPricesMap := keeper.CreatePricesMap(latestPrices.Prices) @@ -101,6 +153,7 @@ func (s *KeeperTestSuite) TestGeneratePricesNotMeetHardDeviation() { tunnel.SignalDeviations, latestPricesMap, pricesMap, + 1733000000, sendAll, ) s.Require().Len(newPrices, 0) diff --git a/x/tunnel/keeper/keeper_latest_prices_test.go b/x/tunnel/keeper/keeper_latest_prices_test.go index e2207f338..205d667c6 100644 --- a/x/tunnel/keeper/keeper_latest_prices_test.go +++ b/x/tunnel/keeper/keeper_latest_prices_test.go @@ -12,7 +12,12 @@ func (s *KeeperTestSuite) TestGetSetLatestPrices() { latestPrices := types.LatestPrices{ TunnelID: tunnelID, Prices: []feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_NOT_IN_CURRENT_FEEDS, SignalID: "BTC", Price: 50000}, + { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:BAND-USD", + Price: 50000, + Timestamp: 1733000000, + }, }, } @@ -29,13 +34,23 @@ func (s *KeeperTestSuite) TestGetAllLatestPrices() { latestPrices1 := types.LatestPrices{ TunnelID: 1, Prices: []feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_NOT_IN_CURRENT_FEEDS, SignalID: "BTC", Price: 50000}, + { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:BAND-USD", + Price: 50000, + Timestamp: 1733000000, + }, }, } latestPrices2 := types.LatestPrices{ TunnelID: 2, Prices: []feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_NOT_IN_CURRENT_FEEDS, SignalID: "ETH", Price: 3000}, + { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:ETH-USD", + Price: 3000, + Timestamp: 1733000000, + }, }, } diff --git a/x/tunnel/keeper/keeper_packet.go b/x/tunnel/keeper/keeper_packet.go index 7ca2fb00d..784b23ac1 100644 --- a/x/tunnel/keeper/keeper_packet.go +++ b/x/tunnel/keeper/keeper_packet.go @@ -116,7 +116,13 @@ func (k Keeper) ProducePacket( sendAll := unixNow >= int64(tunnel.Interval)+latestPrices.LastInterval // generate newPrices; if no newPrices, stop the process. - newPrices := GenerateNewPrices(tunnel.SignalDeviations, latestPricesMap, feedsPricesMap, sendAll) + newPrices := GenerateNewPrices( + tunnel.SignalDeviations, + latestPricesMap, + feedsPricesMap, + ctx.BlockTime().Unix(), + sendAll, + ) if len(newPrices) == 0 { return nil } diff --git a/x/tunnel/keeper/keeper_packet_test.go b/x/tunnel/keeper/keeper_packet_test.go index 8a58784be..eb8629534 100644 --- a/x/tunnel/keeper/keeper_packet_test.go +++ b/x/tunnel/keeper/keeper_packet_test.go @@ -62,7 +62,7 @@ func (s *KeeperTestSuite) TestCreatePacket() { FeePayer: feePayer.String(), IsActive: true, SignalDeviations: []types.SignalDeviation{ - {SignalID: "BTC/USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, + {SignalID: "CS:BAND-USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, }, CreatedAt: ctx.BlockTime().Unix(), } @@ -71,7 +71,7 @@ func (s *KeeperTestSuite) TestCreatePacket() { DestinationContractAddress: "0x", } prices := []feedstypes.Price{ - {SignalID: "BTC/USD", Price: 0}, + {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "CS:BAND-USD", Price: 5000000, Timestamp: 1733000000}, } s.bandtssKeeper.EXPECT().GetSigningFee(gomock.Any()).Return( @@ -113,7 +113,12 @@ func (s *KeeperTestSuite) TestProducePacket() { tunnelID := uint64(1) pricesMap := map[string]feedstypes.Price{ - "BTC/USD": {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC/USD", Price: 50000, Timestamp: 0}, + "CS:BAND-USD": { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:BAND-USD", + Price: 50000, + Timestamp: 1733000000, + }, } feePayer := sdk.AccAddress([]byte("fee_payer_address")) tunnel := types.Tunnel{ @@ -121,7 +126,7 @@ func (s *KeeperTestSuite) TestProducePacket() { FeePayer: feePayer.String(), IsActive: true, SignalDeviations: []types.SignalDeviation{ - {SignalID: "BTC/USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, + {SignalID: "CS:BAND-USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, }, CreatedAt: ctx.BlockTime().Unix(), } @@ -158,7 +163,7 @@ func (s *KeeperTestSuite) TestProducePacket() { s.Require().NoError(err) k.SetLatestPrices(ctx, types.NewLatestPrices(tunnelID, []feedstypes.Price{ - {SignalID: "BTC/USD", Price: 0}, + {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "CS:BAND-USD", Price: 600000, Timestamp: 1732000000}, }, 0)) err = k.ProducePacket(ctx, tunnelID, pricesMap) @@ -175,7 +180,7 @@ func (s *KeeperTestSuite) TestProduceActiveTunnelPackets() { FeePayer: feePayer.String(), IsActive: true, SignalDeviations: []types.SignalDeviation{ - {SignalID: "BTC/USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, + {SignalID: "CS:BAND-USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, }, CreatedAt: ctx.BlockTime().Unix(), } @@ -189,7 +194,7 @@ func (s *KeeperTestSuite) TestProduceActiveTunnelPackets() { ).Times(2) s.feedsKeeper.EXPECT().GetAllPrices(gomock.Any()).Return([]feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC/USD", Price: 50000, Timestamp: 0}, + {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "CS:BAND-USD", Price: 50000, Timestamp: 1733000000}, }) spendableCoins := types.DefaultBasePacketFee.Add(sdk.NewCoin("uband", sdkmath.NewInt(20))) @@ -220,7 +225,7 @@ func (s *KeeperTestSuite) TestProduceActiveTunnelPackets() { s.Require().NoError(err) k.SetLatestPrices(ctx, types.NewLatestPrices(tunnelID, []feedstypes.Price{ - {SignalID: "BTC/USD", Price: 0}, + {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "CS:BAND-USD", Price: 6000000, Timestamp: 1732000000}, }, 0)) err = k.ProduceActiveTunnelPackets(ctx) @@ -245,7 +250,7 @@ func (s *KeeperTestSuite) TestProduceActiveTunnelPacketsNotEnoughMoney() { FeePayer: feePayer.String(), IsActive: true, SignalDeviations: []types.SignalDeviation{ - {SignalID: "BTC/USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, + {SignalID: "CS:BAND-USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, }, CreatedAt: ctx.BlockTime().Unix(), } @@ -259,7 +264,7 @@ func (s *KeeperTestSuite) TestProduceActiveTunnelPacketsNotEnoughMoney() { ) s.feedsKeeper.EXPECT().GetAllPrices(gomock.Any()).Return([]feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC/USD", Price: 50000, Timestamp: 0}, + {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "CS:BAND-USD", Price: 50000, Timestamp: 1733000000}, }) s.bankKeeper.EXPECT().SpendableCoins(gomock.Any(), feePayer). Return(sdk.Coins{sdk.NewInt64Coin("uband", 1)}) @@ -279,7 +284,7 @@ func (s *KeeperTestSuite) TestProduceActiveTunnelPacketsNotEnoughMoney() { s.Require().NoError(err) k.SetLatestPrices(ctx, types.NewLatestPrices(tunnelID, []feedstypes.Price{ - {SignalID: "BTC/USD", Price: 0}, + {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "CS:BAND-USD", Price: 600000, Timestamp: 1733000000}, }, 0)) err = k.ProduceActiveTunnelPackets(ctx) diff --git a/x/tunnel/keeper/keeper_test.go b/x/tunnel/keeper/keeper_test.go index 26230ca56..1190cb83d 100644 --- a/x/tunnel/keeper/keeper_test.go +++ b/x/tunnel/keeper/keeper_test.go @@ -113,7 +113,7 @@ func (s *KeeperTestSuite) AddSampleTunnel(isActive bool) { signalDeviations := []types.SignalDeviation{ { - SignalID: "BTC", + SignalID: "CS:BAND-USD", SoftDeviationBPS: 100, HardDeviationBPS: 100, }, diff --git a/x/tunnel/keeper/keeper_tunnel_test.go b/x/tunnel/keeper/keeper_tunnel_test.go index 29e890903..2501bd7b4 100644 --- a/x/tunnel/keeper/keeper_tunnel_test.go +++ b/x/tunnel/keeper/keeper_tunnel_test.go @@ -20,8 +20,8 @@ func (s *KeeperTestSuite) TestAddTunnel() { route := &types.TSSRoute{} any, _ := codectypes.NewAnyWithValue(route) signalDeviations := []types.SignalDeviation{ - {SignalID: "BTC"}, - {SignalID: "ETH"}, + {SignalID: "CS:BAND-USD"}, + {SignalID: "CS:CS:ETH-USD-USD"}, } interval := uint64(10) creator := sdk.AccAddress([]byte("creator_address")) @@ -69,8 +69,8 @@ func (s *KeeperTestSuite) TestUpdateAndResetTunnel() { initialRoute := &types.TSSRoute{} initialSignalDeviations := []types.SignalDeviation{ - {SignalID: "BTC", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, - {SignalID: "ETH", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, + {SignalID: "CS:BAND-USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, + {SignalID: "CS:ETH-USD", SoftDeviationBPS: 1000, HardDeviationBPS: 1000}, } initialInterval := uint64(10) creator := sdk.AccAddress([]byte("creator_address")) @@ -92,8 +92,8 @@ func (s *KeeperTestSuite) TestUpdateAndResetTunnel() { // define new test data for editing the tunnel newSignalDeviations := []types.SignalDeviation{ - {SignalID: "BTC", SoftDeviationBPS: 1100, HardDeviationBPS: 1100}, - {SignalID: "ETH", SoftDeviationBPS: 1100, HardDeviationBPS: 1100}, + {SignalID: "CS:BAND-USD", SoftDeviationBPS: 1100, HardDeviationBPS: 1100}, + {SignalID: "CS:ETH-USD", SoftDeviationBPS: 1100, HardDeviationBPS: 1100}, } newInterval := uint64(20) @@ -169,8 +169,8 @@ func (s *KeeperTestSuite) TestActivateTunnel() { tunnelID := uint64(1) route := &codectypes.Any{} signalDeviations := []types.SignalDeviation{ - {SignalID: "BTC"}, - {SignalID: "ETH"}, + {SignalID: "CS:BAND-USD"}, + {SignalID: "CS:ETH-USD"}, } interval := uint64(10) creator := sdk.AccAddress([]byte("creator_address")).String() @@ -207,8 +207,8 @@ func (s *KeeperTestSuite) TestDeactivateTunnel() { tunnelID := uint64(1) route := &codectypes.Any{} signalDeviations := []types.SignalDeviation{ - {SignalID: "BTC"}, - {SignalID: "ETH"}, + {SignalID: "CS:BAND-USD"}, + {SignalID: "CS:ETH-USD"}, } interval := uint64(10) creator := sdk.AccAddress([]byte("creator_address")).String() diff --git a/x/tunnel/keeper/msg_server_test.go b/x/tunnel/keeper/msg_server_test.go index e32553b19..f9d4e9936 100644 --- a/x/tunnel/keeper/msg_server_test.go +++ b/x/tunnel/keeper/msg_server_test.go @@ -16,12 +16,12 @@ import ( func (s *KeeperTestSuite) TestMsgCreateTunnel() { signalDeviations := []types.SignalDeviation{ { - SignalID: "BTC", + SignalID: "CS:BAND-USD", SoftDeviationBPS: 100, HardDeviationBPS: 100, }, { - SignalID: "ETH", + SignalID: "CS:ETH-USD", SoftDeviationBPS: 100, HardDeviationBPS: 100, }, @@ -171,12 +171,12 @@ func (s *KeeperTestSuite) TestMsgUpdateAndResetTunnel() { editedSignalDeviations := []types.SignalDeviation{ { - SignalID: "BTC", + SignalID: "CS:BAND-USD", SoftDeviationBPS: 200, HardDeviationBPS: 200, }, { - SignalID: "ETH", + SignalID: "CS:ETH-USD", SoftDeviationBPS: 200, HardDeviationBPS: 200, }, @@ -204,7 +204,7 @@ func (s *KeeperTestSuite) TestMsgUpdateAndResetTunnel() { editedSignalDeviations := []types.SignalDeviation{ { - SignalID: "BTC", + SignalID: "CS:BAND-USD", SoftDeviationBPS: 200, HardDeviationBPS: 200, }, @@ -231,7 +231,7 @@ func (s *KeeperTestSuite) TestMsgUpdateAndResetTunnel() { editedSignalDeviations := []types.SignalDeviation{ { - SignalID: "BTC", + SignalID: "CS:BAND-USD", SoftDeviationBPS: 200, HardDeviationBPS: 200, }, @@ -279,7 +279,7 @@ func (s *KeeperTestSuite) TestMsgUpdateAndResetTunnel() { editedSignalDeviations := []types.SignalDeviation{ { - SignalID: "BTC", + SignalID: "CS:BAND-USD", SoftDeviationBPS: 200, HardDeviationBPS: 200, }, @@ -503,9 +503,16 @@ func (s *KeeperTestSuite) TestMsgTriggerTunnel() { sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(20))), ).Return(bandtsstypes.SigningID(1), nil) - s.feedsKeeper.EXPECT().GetPrices(gomock.Any(), []string{"BTC"}).Return([]feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "BTC", Price: 50000, Timestamp: 0}, - }) + s.feedsKeeper.EXPECT(). + GetPrices(gomock.Any(), []string{"CS:BAND-USD"}). + Return([]feedstypes.Price{ + { + Status: feedstypes.PRICE_STATUS_AVAILABLE, + SignalID: "CS:BAND-USD", + Price: 50000, + Timestamp: 0, + }, + }) s.bankKeeper.EXPECT(). SendCoinsFromAccountToModule(gomock.Any(), feePayer, types.ModuleName, types.DefaultBasePacketFee). Return(nil) diff --git a/x/tunnel/types/encoding_tss_test.go b/x/tunnel/types/encoding_tss_test.go index 0c23a1268..26dd91367 100644 --- a/x/tunnel/types/encoding_tss_test.go +++ b/x/tunnel/types/encoding_tss_test.go @@ -17,13 +17,13 @@ func TestEncodeTSSFixedPrice(t *testing.T) { "0000000000000000000000000000000000000000000000000000000000000060" + "000000000000000000000000000000000000000000000000000000000000007b" + "0000000000000000000000000000000000000000000000000000000000000001" + - "00000000000000000000000000000000000000000000007369676e616c5f3031" + + "00000000000000000000000000000000000000000043533a42414e442d555344" + "0000000000000000000000000000000000000000000000000000000000000002") msg, err := types.EncodeTSS( 3, []feedstypes.Price{ - {SignalID: "signal_01", Price: 2, Status: feedstypes.PRICE_STATUS_AVAILABLE}, + {SignalID: "CS:BAND-USD", Price: 2, Status: feedstypes.PRICE_STATUS_AVAILABLE}, }, 123, feedstypes.ENCODER_FIXED_POINT_ABI, @@ -40,13 +40,13 @@ func TestEncodeTSSTick(t *testing.T) { "0000000000000000000000000000000000000000000000000000000000000060" + "000000000000000000000000000000000000000000000000000000000000007b" + "0000000000000000000000000000000000000000000000000000000000000001" + - "00000000000000000000000000000000000000000000007369676e616c5f3031" + + "00000000000000000000000000000000000000000043533a42414e442d555344" + "000000000000000000000000000000000000000000000000000000000000f188") msg, err := types.EncodeTSS( 3, []feedstypes.Price{ - {SignalID: "signal_01", Price: 2, Status: feedstypes.PRICE_STATUS_AVAILABLE}, + {SignalID: "CS:BAND-USD", Price: 2, Status: feedstypes.PRICE_STATUS_AVAILABLE}, }, 123, feedstypes.ENCODER_TICK_ABI, diff --git a/x/tunnel/types/latest_prices_test.go b/x/tunnel/types/latest_prices_test.go index 9d63895d4..9ab03c8a6 100644 --- a/x/tunnel/types/latest_prices_test.go +++ b/x/tunnel/types/latest_prices_test.go @@ -11,13 +11,13 @@ import ( func TestLatestPrices_UpdatePrices(t *testing.T) { initialPrices := []feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "signal1", Price: 100}, + {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "signal1", Price: 100, Timestamp: 1732000000}, } latestPrices := types.NewLatestPrices(1, initialPrices, 10) newPrices := []feedstypes.Price{ - {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "signal1", Price: 200}, - {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "signal2", Price: 300}, + {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "signal1", Price: 200, Timestamp: 1733000000}, + {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "signal2", Price: 300, Timestamp: 1733000000}, } latestPrices.UpdatePrices(newPrices) diff --git a/x/tunnel/types/route_ibc_test.go b/x/tunnel/types/route_ibc_test.go index 26b91d30f..44c3093b3 100644 --- a/x/tunnel/types/route_ibc_test.go +++ b/x/tunnel/types/route_ibc_test.go @@ -13,14 +13,16 @@ func TestGetByteTunnelPricesPacketData(t *testing.T) { packet := types.NewTunnelPricesPacketData( 1, 2, - []feedstypes.Price{{Status: feedstypes.PRICE_STATUS_NOT_IN_CURRENT_FEEDS, SignalID: "BTC", Price: 50000}}, + []feedstypes.Price{ + {Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "CS:BAND-USD", Price: 50000, Timestamp: 1733000000}, + }, 1633024800, ) require.Equal( t, []byte( - `{"created_at":"1633024800","prices":[{"price":"50000","signal_id":"BTC","status":"PRICE_STATUS_NOT_IN_CURRENT_FEEDS","timestamp":"0"}],"sequence":"2","tunnel_id":"1"}`, + `{"created_at":"1633024800","prices":[{"price":"50000","signal_id":"CS:BAND-USD","status":"PRICE_STATUS_AVAILABLE","timestamp":"1733000000"}],"sequence":"2","tunnel_id":"1"}`, ), packet.GetBytes(), ) From d6fe0f617f65f7ee9af5a81c9c7ed18db0313dc9 Mon Sep 17 00:00:00 2001 From: Kitipong Sirirueangsakul Date: Tue, 3 Dec 2024 03:18:18 +0700 Subject: [PATCH 2/2] fix typo --- scripts/tunnel/signal_deviations.json | 4 ++-- x/tunnel/keeper/keeper_tunnel_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/tunnel/signal_deviations.json b/scripts/tunnel/signal_deviations.json index caab898bb..a2239d4f5 100644 --- a/scripts/tunnel/signal_deviations.json +++ b/scripts/tunnel/signal_deviations.json @@ -2,11 +2,11 @@ "signal_deviations": [ { "signal_id": "CS:BTC-USD", - "deviation_bps": 2000 + "deviation_bps": 200 }, { "signal_id": "CS:ETH-USD", - "deviation_bps": 3000 + "deviation_bps": 400 } ] } diff --git a/x/tunnel/keeper/keeper_tunnel_test.go b/x/tunnel/keeper/keeper_tunnel_test.go index 2501bd7b4..bd4e88326 100644 --- a/x/tunnel/keeper/keeper_tunnel_test.go +++ b/x/tunnel/keeper/keeper_tunnel_test.go @@ -21,7 +21,7 @@ func (s *KeeperTestSuite) TestAddTunnel() { any, _ := codectypes.NewAnyWithValue(route) signalDeviations := []types.SignalDeviation{ {SignalID: "CS:BAND-USD"}, - {SignalID: "CS:CS:ETH-USD-USD"}, + {SignalID: "CS:ETH-USD"}, } interval := uint64(10) creator := sdk.AccAddress([]byte("creator_address"))