diff --git a/x/data-proxy/keeper/common_test.go b/x/data-proxy/keeper/common_test.go index cc09c84b..889a4bfc 100644 --- a/x/data-proxy/keeper/common_test.go +++ b/x/data-proxy/keeper/common_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/suite" + "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" @@ -76,3 +77,16 @@ func (s *KeeperTestSuite) SetupTest() { err := s.keeper.Params.Set(s.ctx, types.DefaultParams()) s.Require().NoError(err) } + +func (s *KeeperTestSuite) NewIntFromString(val string) math.Int { + amount, success := math.NewIntFromString(val) + s.Require().True(success) + return amount +} + +func (s *KeeperTestSuite) NewFeeFromString(val string) *sdk.Coin { + return &sdk.Coin{ + Denom: "aseda", + Amount: s.NewIntFromString(val), + } +} diff --git a/x/data-proxy/keeper/msg_server_test.go b/x/data-proxy/keeper/msg_server_test.go index 1ee833f2..3b5f5978 100644 --- a/x/data-proxy/keeper/msg_server_test.go +++ b/x/data-proxy/keeper/msg_server_test.go @@ -4,19 +4,10 @@ import ( "encoding/hex" "cosmossdk.io/collections" - "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sedaprotocol/seda-chain/x/data-proxy/types" ) -func (s *KeeperTestSuite) NewIntFromString(val string) math.Int { - amount, success := math.NewIntFromString(val) - s.Require().True(success) - return amount -} - func (s *KeeperTestSuite) TestMsgServer_RegisterDataProxy() { tests := []struct { name string @@ -29,23 +20,17 @@ func (s *KeeperTestSuite) TestMsgServer_RegisterDataProxy() { msg: &types.MsgRegisterDataProxy{ AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", PayoutAddress: "seda1wyzxdtpl0c99c92n397r3drlhj09qfjvf6teyh", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("10000000000000000000"), - }, - Memo: "", - PubKey: "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", - Signature: "628e5f1a2662872636c91fe2103602b2f0d5b0c3a52c5cc564171b424b902612048704f4a3349c70f0d0c618ecc65aa884c545e717d94be2272a4f2d6021fa6b", + Fee: s.NewFeeFromString("10000000000000000000"), + Memo: "", + PubKey: "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", + Signature: "628e5f1a2662872636c91fe2103602b2f0d5b0c3a52c5cc564171b424b902612048704f4a3349c70f0d0c618ecc65aa884c545e717d94be2272a4f2d6021fa6b", }, expected: &types.ProxyConfig{ PayoutAddress: "seda1wyzxdtpl0c99c92n397r3drlhj09qfjvf6teyh", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("10000000000000000000"), - }, - Memo: "", - FeeUpdate: nil, - AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", + Fee: s.NewFeeFromString("10000000000000000000"), + Memo: "", + FeeUpdate: nil, + AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", }, wantErr: nil, }, @@ -54,23 +39,17 @@ func (s *KeeperTestSuite) TestMsgServer_RegisterDataProxy() { msg: &types.MsgRegisterDataProxy{ AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", PayoutAddress: "seda1wyzxdtpl0c99c92n397r3drlhj09qfjvf6teyh", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("9000000000000000000"), - }, - Memo: "This is a sweet proxy", - PubKey: "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", - Signature: "65b010f830dd52d54c940cec63140354e99484e4a2db9df3e0a7524a4bfaf87e146c82faddcba00df59e57dd774fb147994fbccea16be841e60e9791ccdbb4c4", + Fee: s.NewFeeFromString("9000000000000000000"), + Memo: "This is a sweet proxy", + PubKey: "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", + Signature: "65b010f830dd52d54c940cec63140354e99484e4a2db9df3e0a7524a4bfaf87e146c82faddcba00df59e57dd774fb147994fbccea16be841e60e9791ccdbb4c4", }, expected: &types.ProxyConfig{ PayoutAddress: "seda1wyzxdtpl0c99c92n397r3drlhj09qfjvf6teyh", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("9000000000000000000"), - }, - Memo: "This is a sweet proxy", - FeeUpdate: nil, - AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", + Fee: s.NewFeeFromString("9000000000000000000"), + Memo: "This is a sweet proxy", + FeeUpdate: nil, + AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", }, wantErr: nil, }, @@ -79,13 +58,10 @@ func (s *KeeperTestSuite) TestMsgServer_RegisterDataProxy() { msg: &types.MsgRegisterDataProxy{ AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", PayoutAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("10000000000000000000"), - }, - Memo: "", - PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", - Signature: "5076d9d98754505d2f6f94f5a44062b9e95c2c5cfe7f21c69270814dc947bd285f5ed64e595aa956004687a225263f2831252cb41379cab2e3505b90f3da2701", + Fee: s.NewFeeFromString("10000000000000000000"), + Memo: "", + PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", + Signature: "5076d9d98754505d2f6f94f5a44062b9e95c2c5cfe7f21c69270814dc947bd285f5ed64e595aa956004687a225263f2831252cb41379cab2e3505b90f3da2701", }, expected: nil, wantErr: types.ErrInvalidAddress, @@ -95,13 +71,10 @@ func (s *KeeperTestSuite) TestMsgServer_RegisterDataProxy() { msg: &types.MsgRegisterDataProxy{ AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", PayoutAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("9000000000000000000"), - }, - Memo: "", - PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", - Signature: "5076d9d98754505d2f6f94f5a44062b9e95c2c5cfe7f21c69270814dc947bd285f5ed64e595aa956004687a225263f2831252cb41379cab2e3505b90f3da2701", + Fee: s.NewFeeFromString("9000000000000000000"), + Memo: "", + PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", + Signature: "5076d9d98754505d2f6f94f5a44062b9e95c2c5cfe7f21c69270814dc947bd285f5ed64e595aa956004687a225263f2831252cb41379cab2e3505b90f3da2701", }, expected: nil, wantErr: types.ErrInvalidSignature, @@ -111,13 +84,10 @@ func (s *KeeperTestSuite) TestMsgServer_RegisterDataProxy() { msg: &types.MsgRegisterDataProxy{ AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", PayoutAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("10000000000000000000"), - }, - Memo: "", - PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3", - Signature: "5076d9d98754505d2f6f94f5a44062b9e95c2c5cfe7f21c69270814dc947bd285f5ed64e595aa956004687a225263f2831252cb41379cab2e3505b90f3da2701", + Fee: s.NewFeeFromString("10000000000000000000"), + Memo: "", + PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3", + Signature: "5076d9d98754505d2f6f94f5a44062b9e95c2c5cfe7f21c69270814dc947bd285f5ed64e595aa956004687a225263f2831252cb41379cab2e3505b90f3da2701", }, expected: nil, wantErr: types.ErrInvalidHex, @@ -127,13 +97,10 @@ func (s *KeeperTestSuite) TestMsgServer_RegisterDataProxy() { msg: &types.MsgRegisterDataProxy{ AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", PayoutAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("10000000000000000000"), - }, - Memo: "", - PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4f3", - Signature: "5076g9d98754505d2f6f94f5a44062b9e95c2c5cfe7f21c69270814dc947bd285f5ed64e595aa956004687a225263f2831252cb41379cab2e3505b90f3da2701", + Fee: s.NewFeeFromString("10000000000000000000"), + Memo: "", + PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4f3", + Signature: "5076g9d98754505d2f6f94f5a44062b9e95c2c5cfe7f21c69270814dc947bd285f5ed64e595aa956004687a225263f2831252cb41379cab2e3505b90f3da2701", }, expected: nil, wantErr: types.ErrInvalidHex, @@ -162,11 +129,8 @@ func (s *KeeperTestSuite) TestMsgServer_RegisterDataProxy() { msg := &types.MsgRegisterDataProxy{ AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", PayoutAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("10000000000000000000"), - }, - Memo: "", + Fee: s.NewFeeFromString("10000000000000000000"), + PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", Signature: "5076d9d98754505d2f6f94f5a44062b9e95c2c5cfe7f21c69270814dc947bd285f5ed64e595aa956004687a225263f2831252cb41379cab2e3505b90f3da2701", } @@ -178,13 +142,10 @@ func (s *KeeperTestSuite) TestMsgServer_RegisterDataProxy() { s.Require().NoError(err) s.Require().Equal(&types.ProxyConfig{ PayoutAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("10000000000000000000"), - }, - Memo: "", - FeeUpdate: nil, - AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", + Fee: s.NewFeeFromString("10000000000000000000"), + Memo: "", + FeeUpdate: nil, + AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", }, &proxyConfig) res, err := s.msgSrvr.RegisterDataProxy(s.ctx, msg) @@ -199,13 +160,10 @@ func (s *KeeperTestSuite) TestMsgServer_EditDataProxy() { initialProxyConfig := types.ProxyConfig{ PayoutAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("9"), - }, - Memo: "test", - FeeUpdate: nil, - AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", + Fee: s.NewFeeFromString("9"), + Memo: "test", + FeeUpdate: nil, + AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", } tests := []struct { @@ -224,13 +182,10 @@ func (s *KeeperTestSuite) TestMsgServer_EditDataProxy() { }, expected: &types.ProxyConfig{ PayoutAddress: "seda1wyzxdtpl0c99c92n397r3drlhj09qfjvf6teyh", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("9"), - }, - Memo: "test", - FeeUpdate: nil, - AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", + Fee: s.NewFeeFromString("9"), + Memo: "test", + FeeUpdate: nil, + AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", }, wantErr: nil, }, @@ -244,13 +199,10 @@ func (s *KeeperTestSuite) TestMsgServer_EditDataProxy() { }, expected: &types.ProxyConfig{ PayoutAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("9"), - }, - Memo: "", - FeeUpdate: nil, - AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", + Fee: s.NewFeeFromString("9"), + Memo: "", + FeeUpdate: nil, + AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", }, wantErr: nil, }, @@ -260,24 +212,15 @@ func (s *KeeperTestSuite) TestMsgServer_EditDataProxy() { Sender: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", NewPayoutAddress: types.DoNotModifyField, NewMemo: types.DoNotModifyField, - NewFee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("1337"), - }, - PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", + NewFee: s.NewFeeFromString("1337"), + PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", }, expected: &types.ProxyConfig{ PayoutAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("9"), - }, - Memo: "test", + Fee: s.NewFeeFromString("9"), + Memo: "test", FeeUpdate: &types.FeeUpdate{ - NewFee: sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("1337"), - }, + NewFee: *s.NewFeeFromString("1337"), // Height in test is 0, so update height should be minimum UpdateHeight: int64(types.DefaultMinFeeUpdateDelay), }, @@ -291,25 +234,16 @@ func (s *KeeperTestSuite) TestMsgServer_EditDataProxy() { Sender: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", NewPayoutAddress: types.DoNotModifyField, NewMemo: types.DoNotModifyField, - NewFee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("1337"), - }, - FeeUpdateDelay: types.DefaultMinFeeUpdateDelay + 100, - PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", + NewFee: s.NewFeeFromString("1337"), + FeeUpdateDelay: types.DefaultMinFeeUpdateDelay + 100, + PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", }, expected: &types.ProxyConfig{ PayoutAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", - Fee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("9"), - }, - Memo: "test", + Fee: s.NewFeeFromString("9"), + Memo: "test", FeeUpdate: &types.FeeUpdate{ - NewFee: sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("1337"), - }, + NewFee: *s.NewFeeFromString("1337"), UpdateHeight: int64(types.DefaultMinFeeUpdateDelay + 100), }, AdminAddress: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", @@ -322,12 +256,9 @@ func (s *KeeperTestSuite) TestMsgServer_EditDataProxy() { Sender: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", NewPayoutAddress: types.DoNotModifyField, NewMemo: types.DoNotModifyField, - NewFee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("1337"), - }, - FeeUpdateDelay: 1, - PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", + NewFee: s.NewFeeFromString("1337"), + FeeUpdateDelay: 1, + PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", }, expected: nil, wantErr: types.ErrInvalidDelay, @@ -385,12 +316,9 @@ func (s *KeeperTestSuite) TestMsgServer_EditDataProxy() { Sender: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", NewPayoutAddress: types.DoNotModifyField, NewMemo: types.DoNotModifyField, - NewFee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("1337"), - }, - FeeUpdateDelay: uint32(firstUpdateHeight), - PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", + NewFee: s.NewFeeFromString("1337"), + FeeUpdateDelay: uint32(firstUpdateHeight), + PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", } firstRes, err := s.msgSrvr.EditDataProxy(s.ctx, firstMsg) @@ -409,12 +337,9 @@ func (s *KeeperTestSuite) TestMsgServer_EditDataProxy() { Sender: "seda1uea9km4nup9q7qu96ak683kc67x9jf7ste45z5", NewPayoutAddress: types.DoNotModifyField, NewMemo: types.DoNotModifyField, - NewFee: &sdk.Coin{ - Denom: "aseda", - Amount: s.NewIntFromString("1984"), - }, - FeeUpdateDelay: uint32(secondUpdateHeight), - PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", + NewFee: s.NewFeeFromString("1984"), + FeeUpdateDelay: uint32(secondUpdateHeight), + PubKey: "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", } secondRes, err := s.msgSrvr.EditDataProxy(s.ctx, secondMsg)