From 3f9412abc3d787927b2a0d6b197131cdbf3e3537 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Fri, 2 Jun 2023 14:39:57 +0100 Subject: [PATCH 01/25] front-port v1.2.13 --- go.mod | 2 +- go.sum | 4 +- .../interchainquery/v1/query.proto | 14 +- x/airdrop/types/messages.pb.go | 80 +++++----- x/interchainquery/types/messages.pb.go | 10 +- x/interchainquery/types/query.pb.go | 132 +++++++++++----- x/interchainstaking/keeper/callbacks.go | 146 +++++++++++++++++- .../keeper/ibc_packet_handlers.go | 61 +++++--- x/interchainstaking/keeper/keeper.go | 2 + x/interchainstaking/keeper/receipt.go | 73 +++++---- x/interchainstaking/types/messages.pb.go | 80 +++++----- x/participationrewards/types/messages.pb.go | 56 +++---- 12 files changed, 442 insertions(+), 218 deletions(-) diff --git a/go.mod b/go.mod index ebef48fe6..41a49bf91 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/cometbft/cometbft-db v0.8.0 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.46.12 - github.com/cosmos/ibc-go/v5 v5.2.0 + github.com/cosmos/ibc-go/v5 v5.2.1 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.3 github.com/golangci/golangci-lint v1.53.1 diff --git a/go.sum b/go.sum index 174d12fd9..0326e7f1c 100644 --- a/go.sum +++ b/go.sum @@ -394,8 +394,8 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek= github.com/cosmos/iavl v0.19.5 h1:rGA3hOrgNxgRM5wYcSCxgQBap7fW82WZgY78V9po/iY= github.com/cosmos/iavl v0.19.5/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= -github.com/cosmos/ibc-go/v5 v5.2.0 h1:LxwttRQqdUJpQ3/Gc3XPg5lkRo3pcbzx65dxFIY6ONE= -github.com/cosmos/ibc-go/v5 v5.2.0/go.mod h1:MhDUMDVSboK5JW2pEWHNcw0wJHaHqKV/vwwP7awGhzI= +github.com/cosmos/ibc-go/v5 v5.2.1 h1:i8Kl9KZfPJVYuihjbGPnjTQWecXQfRLz+QrjJGhzY9o= +github.com/cosmos/ibc-go/v5 v5.2.1/go.mod h1:eH18ghfqGGT9gDCTMDLWg1zPLXplSnPxXRNWPx98xhU= github.com/cosmos/interchain-accounts v0.3.2 h1:7S5rSndahpjkzUvG00kKZrTZsEuVHuVC9a7p0qDVcF8= github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA= github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI= diff --git a/proto/quicksilver/interchainquery/v1/query.proto b/proto/quicksilver/interchainquery/v1/query.proto index e5b035dca..adf51853c 100644 --- a/proto/quicksilver/interchainquery/v1/query.proto +++ b/proto/quicksilver/interchainquery/v1/query.proto @@ -16,7 +16,8 @@ option go_package = "github.com/ingenuity-build/quicksilver/x/interchainquery/ty service QuerySrvr { // Params returns the total set of minting parameters. rpc Queries(QueryRequestsRequest) returns (QueryRequestsResponse) { - option (google.api.http).get = "/quicksilver/interchainquery/v1/queries/{chain_id}"; + option (google.api.http).get = + "/quicksilver/interchainquery/v1/queries/{chain_id}"; } } @@ -29,18 +30,21 @@ message QueryRequestsRequest { // QueryParamsResponse is the response type for the Query/Params RPC method. message QueryRequestsResponse { // params defines the parameters of the module. - repeated quicksilver.interchainquery.v1.Query queries = 1 [(gogoproto.nullable) = false]; + repeated quicksilver.interchainquery.v1.Query queries = 1 + [ (gogoproto.nullable) = false ]; cosmos.base.query.v1beta1.PageResponse pagination = 2; } // GetTxResponse is the response type for the Service.GetTx method. message GetTxWithProofResponse { - // tx is the queried transaction. - cosmos.tx.v1beta1.Tx tx = 1; + // tx is the queried transaction; deprecated. + cosmos.tx.v1beta1.Tx tx = 1; // deprecated, v1.2.13 // tx_response is the queried TxResponses. - cosmos.base.abci.v1beta1.TxResponse tx_response = 2; + cosmos.base.abci.v1beta1.TxResponse tx_response = 2; // deprecated, v1.2.13 // proof is the tmproto.TxProof for the queried tx tendermint.types.TxProof proof = 3; // ibc-go header to validate txs ibc.lightclients.tendermint.v1.Header header = 4; + // tx_bytes is the byte representation of the queried tx + bytes tx_bytes = 5; } diff --git a/x/airdrop/types/messages.pb.go b/x/airdrop/types/messages.pb.go index 9dc1eb326..901960934 100644 --- a/x/airdrop/types/messages.pb.go +++ b/x/airdrop/types/messages.pb.go @@ -202,46 +202,46 @@ func init() { var fileDescriptor_2b0828c7de1949a1 = []byte{ // 659 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x3d, 0x6f, 0x13, 0x4d, - 0x10, 0xf6, 0xd9, 0x79, 0xf3, 0xb1, 0xaf, 0xde, 0x0f, 0x8e, 0x10, 0x1c, 0x0b, 0xee, 0xac, 0x43, - 0x91, 0x4c, 0x90, 0xef, 0xe2, 0x00, 0x41, 0x72, 0x87, 0x43, 0x93, 0x22, 0x28, 0x72, 0x3a, 0x1a, - 0x6b, 0x7d, 0xb7, 0x6c, 0x56, 0xb9, 0xdb, 0x39, 0x6e, 0xd7, 0x56, 0xdc, 0xa1, 0x48, 0x48, 0x94, - 0x48, 0xfc, 0x81, 0xd4, 0x54, 0x14, 0x88, 0x9e, 0x2e, 0x65, 0x04, 0x0d, 0x95, 0x41, 0x09, 0x12, - 0xd4, 0xf9, 0x05, 0xe8, 0xf6, 0xf6, 0x1c, 0x5b, 0x84, 0x44, 0x54, 0xde, 0x9b, 0x79, 0x9e, 0xf9, - 0x78, 0x66, 0xc6, 0x68, 0xe9, 0x59, 0x8f, 0xf9, 0xbb, 0x82, 0x85, 0x7d, 0x92, 0x78, 0x98, 0x25, - 0x41, 0x02, 0xb1, 0xd7, 0x6f, 0x78, 0x11, 0x11, 0x02, 0x53, 0x22, 0xdc, 0x38, 0x01, 0x09, 0xe6, - 0xc2, 0x18, 0xcc, 0xd5, 0x30, 0xb7, 0xdf, 0xa8, 0x58, 0x3e, 0x88, 0x08, 0x84, 0xd7, 0xc5, 0x82, - 0x78, 0xfd, 0x46, 0x97, 0x48, 0xdc, 0xf0, 0x7c, 0x60, 0x3c, 0xe3, 0x55, 0xae, 0x6b, 0x7f, 0x24, - 0xa8, 0x8a, 0x2a, 0xa8, 0x76, 0x2c, 0x66, 0x8e, 0x8e, 0xfa, 0xf2, 0xb2, 0x0f, 0xed, 0x9a, 0xa7, - 0x40, 0x21, 0xb3, 0xa7, 0x2f, 0x6d, 0xbd, 0x41, 0x01, 0x68, 0x48, 0x3c, 0x1c, 0x33, 0x0f, 0x73, - 0x0e, 0x12, 0x4b, 0x06, 0x3c, 0xe7, 0xac, 0x8c, 0xb7, 0xe1, 0x87, 0x98, 0x45, 0x22, 0xc2, 0x1c, - 0x53, 0x92, 0xa4, 0x69, 0x27, 0x0c, 0x19, 0xc3, 0x79, 0x51, 0x44, 0xb3, 0x9b, 0x82, 0xae, 0xa7, - 0x2e, 0xd3, 0x45, 0xb3, 0xfe, 0x0e, 0x66, 0xbc, 0xc3, 0x82, 0xb2, 0x51, 0x35, 0x6a, 0x73, 0xad, - 0xab, 0xa7, 0x43, 0xfb, 0xbf, 0x01, 0x8e, 0xc2, 0xa6, 0x93, 0x7b, 0x9c, 0xf6, 0x8c, 0x7a, 0x6e, - 0x04, 0xe6, 0x6d, 0x34, 0x8d, 0xfd, 0x34, 0x7f, 0xb9, 0x58, 0x35, 0x6a, 0xa5, 0xd6, 0x95, 0xd3, - 0xa1, 0xfd, 0x4f, 0x86, 0xce, 0xec, 0x4e, 0x5b, 0x03, 0xcc, 0x47, 0x68, 0x06, 0x07, 0x41, 0x42, - 0x84, 0x28, 0x97, 0x54, 0xe4, 0xe5, 0xd3, 0xa1, 0xfd, 0xaf, 0xc6, 0x66, 0x0e, 0xe7, 0xe3, 0xbb, - 0xfa, 0xbc, 0x96, 0xe0, 0x61, 0x66, 0xda, 0x96, 0x09, 0xe3, 0xb4, 0x9d, 0x53, 0xcd, 0xc7, 0x68, - 0x3a, 0x4e, 0x00, 0x9e, 0x8a, 0xf2, 0x54, 0xb5, 0x54, 0xfb, 0x7b, 0xf5, 0x96, 0x3b, 0x3e, 0x90, - 0xc9, 0xfe, 0xfa, 0x0d, 0x77, 0x2b, 0xc5, 0x8e, 0x57, 0x95, 0x91, 0x9d, 0xb6, 0x8e, 0xd2, 0x9c, - 0x7d, 0x79, 0x60, 0x17, 0x7e, 0x1c, 0xd8, 0x05, 0x67, 0x1d, 0xfd, 0x9f, 0xcb, 0xd0, 0x26, 0x22, - 0x06, 0x2e, 0x88, 0x6a, 0x2f, 0x82, 0x1e, 0x97, 0x4a, 0x8c, 0xa9, 0x89, 0xf6, 0x94, 0x3d, 0x6d, - 0x4f, 0x3d, 0x9a, 0x53, 0x69, 0xa0, 0x54, 0xcc, 0x6b, 0x9b, 0x82, 0x6e, 0x70, 0x9f, 0x70, 0xc9, - 0xfa, 0x64, 0x0b, 0x20, 0xdc, 0x8e, 0x09, 0x0f, 0xcc, 0x35, 0x34, 0x87, 0x7b, 0x72, 0x07, 0x12, - 0x26, 0x07, 0x5a, 0xda, 0xf2, 0x6f, 0xdb, 0x3d, 0x83, 0x9a, 0x0f, 0x10, 0x92, 0xd0, 0xc9, 0x95, - 0x2b, 0x5e, 0x46, 0x94, 0xa0, 0x0d, 0xa6, 0x3f, 0xaa, 0xbd, 0xa4, 0x94, 0x5a, 0x74, 0x35, 0x23, - 0x5d, 0x51, 0x57, 0xaf, 0xa8, 0xbb, 0x0e, 0x8c, 0xb7, 0x56, 0x0e, 0x87, 0x76, 0xe1, 0xcd, 0x17, - 0xbb, 0x46, 0x99, 0xdc, 0xe9, 0x75, 0x5d, 0x1f, 0x22, 0xbd, 0x89, 0xfa, 0xa7, 0x2e, 0x82, 0x5d, - 0x4f, 0x0e, 0x62, 0x22, 0x14, 0x41, 0x8c, 0xba, 0x5e, 0xc8, 0xe5, 0xdb, 0xff, 0xfe, 0x76, 0xf9, - 0xac, 0x6a, 0xc7, 0x46, 0x37, 0xcf, 0x95, 0x21, 0x57, 0x76, 0xf5, 0x43, 0x11, 0x95, 0x36, 0x05, - 0x35, 0x9f, 0x1b, 0xe8, 0xaf, 0x6c, 0xf5, 0xaa, 0xee, 0xf9, 0xa7, 0xe5, 0xe6, 0x53, 0xa9, 0xd4, - 0x2e, 0x43, 0xe4, 0xd1, 0x9d, 0x3b, 0xfb, 0x9f, 0xbe, 0xbd, 0x2e, 0x2e, 0x35, 0x8d, 0x65, 0xa7, - 0xea, 0x8d, 0x5f, 0x84, 0xdc, 0x4b, 0xcf, 0x20, 0x3f, 0x6f, 0xb5, 0x2e, 0xe6, 0x7b, 0x03, 0x99, - 0xe7, 0x0c, 0xac, 0x7e, 0x41, 0xb6, 0x5f, 0xe1, 0x95, 0xfb, 0x7f, 0x04, 0x1f, 0x55, 0xda, 0x54, - 0x95, 0xde, 0x4b, 0x2b, 0xf5, 0x2e, 0xa8, 0x94, 0xe5, 0x11, 0x3a, 0x31, 0x40, 0xd8, 0x11, 0x69, - 0x8c, 0xd6, 0xd6, 0xe1, 0xb1, 0x65, 0x1c, 0x1d, 0x5b, 0xc6, 0xd7, 0x63, 0xcb, 0x78, 0x75, 0x62, - 0x15, 0x8e, 0x4e, 0xac, 0xc2, 0xe7, 0x13, 0xab, 0xf0, 0x64, 0x6d, 0x6c, 0x90, 0x8c, 0x53, 0xc2, - 0x7b, 0x4c, 0x0e, 0xea, 0xdd, 0x1e, 0x0b, 0x83, 0x89, 0x24, 0x7b, 0xa3, 0x04, 0x6a, 0xb8, 0xdd, - 0x69, 0xf5, 0x97, 0x70, 0xf7, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x30, 0x4e, 0x75, 0x45, 0x0d, + 0x10, 0xf6, 0xd9, 0x79, 0xf3, 0xb1, 0xaf, 0xf8, 0x3a, 0x42, 0x70, 0x2c, 0xf0, 0x59, 0x87, 0x22, + 0x19, 0x23, 0xdf, 0xc5, 0x01, 0x82, 0xe4, 0x0e, 0x87, 0x26, 0x45, 0x50, 0xe4, 0x74, 0x34, 0xd6, + 0xfa, 0x6e, 0xd9, 0xac, 0x72, 0xb7, 0x73, 0xdc, 0xae, 0xad, 0xb8, 0x43, 0x91, 0x90, 0x28, 0x91, + 0xf8, 0x03, 0xa9, 0xa9, 0x28, 0x10, 0x3d, 0x5d, 0xca, 0x08, 0x1a, 0x2a, 0x83, 0x12, 0x24, 0xa8, + 0xf3, 0x0b, 0xd0, 0xed, 0xed, 0x39, 0xb6, 0x08, 0x89, 0xa8, 0xbc, 0x37, 0xf3, 0x3c, 0xf3, 0xf1, + 0xcc, 0x8c, 0xd1, 0xd2, 0x8b, 0x1e, 0xf3, 0x76, 0x04, 0x0b, 0xfa, 0x24, 0x76, 0x31, 0x8b, 0xfd, + 0x18, 0x22, 0xb7, 0xdf, 0x70, 0x43, 0x22, 0x04, 0xa6, 0x44, 0x38, 0x51, 0x0c, 0x12, 0xcc, 0x85, + 0x31, 0x98, 0xa3, 0x61, 0x4e, 0xbf, 0x51, 0x2a, 0x7b, 0x20, 0x42, 0x10, 0x6e, 0x17, 0x0b, 0xe2, + 0xf6, 0x1b, 0x5d, 0x22, 0x71, 0xc3, 0xf5, 0x80, 0xf1, 0x94, 0x57, 0xba, 0xa9, 0xfd, 0xa1, 0xa0, + 0x2a, 0xaa, 0xa0, 0xda, 0xb1, 0x98, 0x3a, 0x3a, 0xea, 0xcb, 0x4d, 0x3f, 0xb4, 0x6b, 0x9e, 0x02, + 0x85, 0xd4, 0x9e, 0xbc, 0xb4, 0xf5, 0x16, 0x05, 0xa0, 0x01, 0x71, 0x71, 0xc4, 0x5c, 0xcc, 0x39, + 0x48, 0x2c, 0x19, 0xf0, 0x8c, 0xb3, 0x3c, 0xde, 0x86, 0x17, 0x60, 0x16, 0x8a, 0x10, 0x73, 0x4c, + 0x49, 0x9c, 0xa4, 0x9d, 0x30, 0xa4, 0x0c, 0xfb, 0x55, 0x1e, 0xcd, 0x6e, 0x08, 0xba, 0x96, 0xb8, + 0x4c, 0x07, 0xcd, 0x7a, 0xdb, 0x98, 0xf1, 0x0e, 0xf3, 0x8b, 0x46, 0xc5, 0xa8, 0xce, 0xb5, 0xae, + 0x9f, 0x0c, 0xad, 0x2b, 0x03, 0x1c, 0x06, 0x4d, 0x3b, 0xf3, 0xd8, 0xed, 0x19, 0xf5, 0x5c, 0xf7, + 0xcd, 0xbb, 0x68, 0x1a, 0x7b, 0x49, 0xfe, 0x62, 0xbe, 0x62, 0x54, 0x0b, 0xad, 0x6b, 0x27, 0x43, + 0xeb, 0x52, 0x8a, 0x4e, 0xed, 0x76, 0x5b, 0x03, 0xcc, 0x27, 0x68, 0x06, 0xfb, 0x7e, 0x4c, 0x84, + 0x28, 0x16, 0x54, 0xe4, 0xda, 0xc9, 0xd0, 0xba, 0xac, 0xb1, 0xa9, 0xc3, 0xfe, 0xfc, 0xa1, 0x3e, + 0xaf, 0x25, 0x78, 0x9c, 0x9a, 0xb6, 0x64, 0xcc, 0x38, 0x6d, 0x67, 0x54, 0xf3, 0x29, 0x9a, 0x8e, + 0x62, 0x80, 0xe7, 0xa2, 0x38, 0x55, 0x29, 0x54, 0xff, 0x5f, 0xb9, 0xe3, 0x8c, 0x0f, 0x64, 0xb2, + 0xbf, 0x7e, 0xc3, 0xd9, 0x4c, 0xb0, 0xe3, 0x55, 0xa5, 0x64, 0xbb, 0xad, 0xa3, 0x34, 0x67, 0x5f, + 0xef, 0x5b, 0xb9, 0x5f, 0xfb, 0x56, 0xce, 0x5e, 0x43, 0x57, 0x33, 0x19, 0xda, 0x44, 0x44, 0xc0, + 0x05, 0x51, 0xed, 0x85, 0xd0, 0xe3, 0x52, 0x89, 0x31, 0x35, 0xd1, 0x9e, 0xb2, 0x27, 0xed, 0xa9, + 0x47, 0x73, 0x2a, 0x09, 0x94, 0x88, 0x79, 0x63, 0x43, 0xd0, 0x75, 0xee, 0x11, 0x2e, 0x59, 0x9f, + 0x6c, 0x02, 0x04, 0x5b, 0x11, 0xe1, 0xbe, 0xb9, 0x8a, 0xe6, 0x70, 0x4f, 0x6e, 0x43, 0xcc, 0xe4, + 0x40, 0x4b, 0x5b, 0xfc, 0x6b, 0xbb, 0xa7, 0x50, 0xf3, 0x11, 0x42, 0x12, 0x3a, 0x99, 0x72, 0xf9, + 0x8b, 0x88, 0x12, 0xb4, 0xc1, 0xf4, 0x46, 0xb5, 0x17, 0x94, 0x52, 0x8b, 0x8e, 0x66, 0x24, 0x2b, + 0xea, 0xe8, 0x15, 0x75, 0xd6, 0x80, 0xf1, 0xd6, 0xf2, 0xc1, 0xd0, 0xca, 0xbd, 0xfb, 0x66, 0x55, + 0x29, 0x93, 0xdb, 0xbd, 0xae, 0xe3, 0x41, 0xa8, 0x37, 0x51, 0xff, 0xd4, 0x85, 0xbf, 0xe3, 0xca, + 0x41, 0x44, 0x84, 0x22, 0x88, 0x51, 0xd7, 0x0b, 0x99, 0x7c, 0x7b, 0x3f, 0xdf, 0xd7, 0x4e, 0xab, + 0xb6, 0x2d, 0x74, 0xfb, 0x4c, 0x19, 0x32, 0x65, 0x57, 0x3e, 0xe5, 0x51, 0x61, 0x43, 0x50, 0xf3, + 0xa5, 0x81, 0xfe, 0x4b, 0x57, 0xaf, 0xe2, 0x9c, 0x7d, 0x5a, 0x4e, 0x36, 0x95, 0x52, 0xf5, 0x22, + 0x44, 0x16, 0xdd, 0xbe, 0xb7, 0xf7, 0xe5, 0xc7, 0xdb, 0xfc, 0x92, 0x5d, 0x71, 0xc7, 0xcf, 0x41, + 0xee, 0x26, 0x37, 0x90, 0xdd, 0xb6, 0xda, 0x95, 0xa6, 0x51, 0x33, 0x3f, 0x1a, 0xc8, 0x3c, 0x63, + 0x60, 0xf5, 0x73, 0xb2, 0xfd, 0x09, 0x2f, 0x3d, 0xfc, 0x27, 0xf8, 0xa8, 0xd2, 0xa6, 0xaa, 0xf4, + 0x81, 0xed, 0x9e, 0x53, 0x29, 0xcb, 0xe8, 0x9d, 0x08, 0x20, 0xe8, 0x88, 0x24, 0x40, 0xd3, 0xa8, + 0xb5, 0x36, 0x0f, 0x8e, 0xca, 0xc6, 0xe1, 0x51, 0xd9, 0xf8, 0x7e, 0x54, 0x36, 0xde, 0x1c, 0x97, + 0x73, 0x87, 0xc7, 0xe5, 0xdc, 0xd7, 0xe3, 0x72, 0xee, 0xd9, 0xea, 0xd8, 0x20, 0x19, 0xa7, 0x84, + 0xf7, 0x98, 0x1c, 0xd4, 0xbb, 0x3d, 0x16, 0xf8, 0x13, 0x79, 0x76, 0x47, 0x39, 0xd4, 0x70, 0xbb, + 0xd3, 0xea, 0x2f, 0xe1, 0xfe, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb2, 0xf6, 0x4f, 0x1d, 0x0d, 0x05, 0x00, 0x00, } diff --git a/x/interchainquery/types/messages.pb.go b/x/interchainquery/types/messages.pb.go index 799f572bd..da9b353d3 100644 --- a/x/interchainquery/types/messages.pb.go +++ b/x/interchainquery/types/messages.pb.go @@ -149,13 +149,13 @@ var fileDescriptor_0640fcbc3e895a79 = []byte{ 0x09, 0xca, 0x48, 0xb0, 0x9b, 0xd1, 0xb9, 0xd4, 0xa9, 0xbc, 0x9e, 0x7a, 0x85, 0x77, 0x53, 0x0f, 0xfc, 0x98, 0x7a, 0x05, 0xbf, 0x6e, 0xb9, 0x9b, 0x7f, 0xf5, 0xea, 0x6c, 0x7f, 0x02, 0x56, 0xe9, 0x50, 0x12, 0xfb, 0x03, 0xb0, 0xf6, 0x36, 0x5d, 0xc9, 0x03, 0xf8, 0xf7, 0xe5, 0x81, 0x9b, 0xf3, - 0xd7, 0xf6, 0xff, 0x2d, 0x6e, 0x75, 0xfa, 0xed, 0x57, 0x5f, 0xbe, 0xbf, 0x2d, 0xde, 0xeb, 0x80, - 0xbb, 0xfe, 0xed, 0x0b, 0x2b, 0xae, 0x4e, 0xd1, 0xb8, 0xd5, 0xc7, 0x2a, 0x6c, 0x21, 0xa9, 0x73, - 0x68, 0xb9, 0xfb, 0xfc, 0xe3, 0xdc, 0x05, 0x67, 0x73, 0x17, 0x7c, 0x9b, 0xbb, 0xe0, 0xcd, 0xc2, + 0xd7, 0xf6, 0xff, 0x2d, 0x6e, 0x75, 0xfa, 0xed, 0x57, 0x5f, 0xbe, 0xbf, 0x2d, 0xde, 0xf3, 0x6f, + 0x5f, 0xd8, 0x6f, 0x75, 0x8a, 0xc6, 0xad, 0x3e, 0x56, 0x61, 0x0b, 0x49, 0x9d, 0x40, 0xcb, 0x1d, + 0x70, 0xb7, 0xfb, 0xfc, 0xe3, 0xdc, 0x05, 0x67, 0x73, 0x17, 0x7c, 0x9b, 0xbb, 0xe0, 0xcd, 0xc2, 0x2d, 0x9c, 0x2d, 0xdc, 0xc2, 0xd7, 0x85, 0x5b, 0x78, 0xb1, 0x4f, 0xa8, 0x1a, 0xa6, 0x7d, 0x38, 0xe0, 0x31, 0xa2, 0x8c, 0x60, 0x96, 0x52, 0x35, 0x69, 0xf6, 0x53, 0x3a, 0x8a, 0xd0, 0xfa, 0x5b, - 0x3a, 0xbd, 0x58, 0x6a, 0x92, 0x60, 0xd9, 0x2f, 0xeb, 0xd5, 0xbd, 0xff, 0x2b, 0x00, 0x00, 0xff, - 0xff, 0xb6, 0xc2, 0x02, 0x03, 0x79, 0x03, 0x00, 0x00, + 0x3a, 0xbd, 0x58, 0x6d, 0x92, 0x60, 0xd9, 0x2f, 0xeb, 0xd5, 0xbd, 0xff, 0x2b, 0x00, 0x00, 0xff, + 0xff, 0x80, 0xb2, 0x83, 0xbd, 0x79, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/interchainquery/types/query.pb.go b/x/interchainquery/types/query.pb.go index 2337d7f60..0e1dd423a 100644 --- a/x/interchainquery/types/query.pb.go +++ b/x/interchainquery/types/query.pb.go @@ -143,7 +143,7 @@ func (m *QueryRequestsResponse) GetPagination() *query.PageResponse { // GetTxResponse is the response type for the Service.GetTx method. type GetTxWithProofResponse struct { - // tx is the queried transaction. + // tx is the queried transaction; deprecated. Tx *tx.Tx `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"` // tx_response is the queried TxResponses. TxResponse *types.TxResponse `protobuf:"bytes,2,opt,name=tx_response,json=txResponse,proto3" json:"tx_response,omitempty"` @@ -151,6 +151,8 @@ type GetTxWithProofResponse struct { Proof *types1.TxProof `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"` // ibc-go header to validate txs Header *types2.Header `protobuf:"bytes,4,opt,name=header,proto3" json:"header,omitempty"` + // tx_bytes is the byte representation of the queried tx + TxBytes []byte `protobuf:"bytes,5,opt,name=tx_bytes,json=txBytes,proto3" json:"tx_bytes,omitempty"` } func (m *GetTxWithProofResponse) Reset() { *m = GetTxWithProofResponse{} } @@ -214,6 +216,13 @@ func (m *GetTxWithProofResponse) GetHeader() *types2.Header { return nil } +func (m *GetTxWithProofResponse) GetTxBytes() []byte { + if m != nil { + return m.TxBytes + } + return nil +} + func init() { proto.RegisterType((*QueryRequestsRequest)(nil), "quicksilver.interchainquery.v1.QueryRequestsRequest") proto.RegisterType((*QueryRequestsResponse)(nil), "quicksilver.interchainquery.v1.QueryRequestsResponse") @@ -225,43 +234,45 @@ func init() { } var fileDescriptor_e4aadfdae61bcbb1 = []byte{ - // 576 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x41, 0x6f, 0xd3, 0x30, - 0x18, 0xad, 0xbb, 0xb1, 0x31, 0xf7, 0x16, 0x6d, 0xa8, 0xab, 0x50, 0xa8, 0x0a, 0x83, 0x6a, 0x12, - 0xb6, 0x5a, 0xca, 0x85, 0xc3, 0x0e, 0x93, 0xc6, 0xe0, 0xb6, 0x85, 0x4a, 0x20, 0x2e, 0x53, 0x92, - 0x9a, 0xd4, 0xa2, 0xb5, 0xd3, 0xf8, 0x4b, 0x94, 0x0a, 0x71, 0xe1, 0x17, 0x20, 0xf1, 0x23, 0xb8, - 0xf3, 0x0b, 0x38, 0xee, 0x38, 0x89, 0x0b, 0x27, 0x84, 0x5a, 0xfe, 0x03, 0x57, 0x14, 0xc7, 0xcd, - 0xd2, 0x22, 0xb1, 0x71, 0x69, 0xed, 0xf8, 0xbd, 0xf7, 0xbd, 0xef, 0xf9, 0x4b, 0xf0, 0xfe, 0x24, - 0xe6, 0xfe, 0x5b, 0xc5, 0x47, 0x09, 0x8b, 0x28, 0x17, 0xc0, 0x22, 0x7f, 0xe8, 0x72, 0x31, 0x89, - 0x59, 0x34, 0xa5, 0x49, 0x87, 0xea, 0x05, 0x09, 0x23, 0x09, 0xd2, 0xb2, 0x4b, 0x58, 0xb2, 0x82, - 0x25, 0x49, 0xa7, 0x71, 0xd7, 0x97, 0x6a, 0x2c, 0x15, 0xf5, 0x5c, 0xc5, 0xa8, 0xeb, 0xf9, 0x9c, - 0x26, 0x1d, 0x8f, 0x81, 0xdb, 0xd1, 0x9b, 0x5c, 0xa4, 0xb1, 0x5f, 0x06, 0x2d, 0xca, 0xe4, 0xa8, - 0xd0, 0x0d, 0xb8, 0x70, 0x81, 0x4b, 0x61, 0xb0, 0x0d, 0x83, 0x85, 0xb4, 0xc0, 0x40, 0x6a, 0xce, - 0xb6, 0x03, 0x19, 0x48, 0xbd, 0xa4, 0xd9, 0xca, 0x3c, 0xbd, 0x1d, 0x48, 0x19, 0x8c, 0x18, 0x75, - 0x43, 0x4e, 0x5d, 0x21, 0x24, 0x68, 0x39, 0x65, 0x4e, 0x29, 0xf7, 0x7c, 0x3a, 0xe2, 0xc1, 0x10, - 0xfc, 0x11, 0x67, 0x02, 0x14, 0x05, 0x26, 0x06, 0x2c, 0x1a, 0x73, 0x01, 0x59, 0xb3, 0x97, 0x3b, - 0x43, 0xe8, 0x5d, 0x91, 0xce, 0x6a, 0x08, 0xc6, 0x44, 0x49, 0x15, 0xa6, 0x21, 0x53, 0xf9, 0x6f, - 0x7e, 0xda, 0x9a, 0xe2, 0xed, 0xd3, 0x0c, 0xec, 0xb0, 0x49, 0xcc, 0x14, 0x28, 0xf3, 0x6f, 0x3d, - 0xc5, 0xf8, 0x32, 0x80, 0x3a, 0x6a, 0xa2, 0x76, 0xad, 0x7b, 0x9f, 0xe4, 0x09, 0x90, 0x2c, 0x2d, - 0xb2, 0x08, 0x5a, 0x27, 0x41, 0x4e, 0xdc, 0x80, 0x19, 0xae, 0x53, 0x62, 0x5a, 0xbb, 0xf8, 0xa6, - 0x76, 0x74, 0xc6, 0x07, 0xf5, 0x6a, 0x13, 0xb5, 0xb7, 0x9c, 0x4d, 0xbd, 0x7f, 0x3e, 0x68, 0x7d, - 0x46, 0x78, 0x67, 0xa5, 0xb6, 0x0a, 0xa5, 0x50, 0xcc, 0x3a, 0xc2, 0x9b, 0x99, 0x3a, 0x67, 0xaa, - 0x8e, 0x9a, 0x6b, 0xed, 0x5a, 0x77, 0x8f, 0xfc, 0xfb, 0xb2, 0x89, 0xd6, 0x39, 0x5c, 0x3f, 0xff, - 0x71, 0xa7, 0xe2, 0x2c, 0xb8, 0xd6, 0xf1, 0x52, 0x0f, 0x55, 0xdd, 0xc3, 0x83, 0x2b, 0x7b, 0xc8, - 0x3d, 0x94, 0x9b, 0x68, 0xfd, 0x46, 0xf8, 0xd6, 0x31, 0x83, 0x7e, 0xfa, 0x92, 0xc3, 0xf0, 0x24, - 0x92, 0xf2, 0x4d, 0x61, 0x75, 0x0f, 0x57, 0x21, 0x35, 0xf9, 0xec, 0x2c, 0xb4, 0x21, 0x2d, 0x34, - 0xfb, 0xa9, 0x53, 0x85, 0xd4, 0x3a, 0xc2, 0x35, 0x48, 0xcf, 0x22, 0xc3, 0x32, 0x5e, 0xee, 0x2d, - 0x79, 0xd1, 0x53, 0x59, 0xa2, 0x15, 0x46, 0xa0, 0x58, 0x5b, 0x14, 0xdf, 0x08, 0xb3, 0xf2, 0xf5, - 0x35, 0x2d, 0xb0, 0x4b, 0x4a, 0x33, 0x92, 0xdf, 0x6a, 0x3f, 0xcd, 0xfd, 0xe5, 0x38, 0xeb, 0x00, - 0x6f, 0x0c, 0x99, 0x3b, 0x60, 0x51, 0x7d, 0xdd, 0x5c, 0x21, 0xf7, 0x7c, 0x52, 0x1e, 0xba, 0xb2, - 0x44, 0xd2, 0x21, 0xcf, 0x34, 0xda, 0x31, 0xac, 0xee, 0x57, 0x84, 0xb7, 0x74, 0xb6, 0x2f, 0xa2, - 0x24, 0xb2, 0xbe, 0x20, 0xbc, 0x79, 0x6a, 0xc2, 0xed, 0x5d, 0xeb, 0x4a, 0x56, 0xc6, 0xaa, 0xf1, - 0xf8, 0x3f, 0x59, 0x79, 0xdf, 0xad, 0x27, 0x1f, 0xbe, 0xfd, 0xfa, 0x54, 0xed, 0x59, 0x5d, 0x7a, - 0x8d, 0x0f, 0x04, 0x67, 0x8a, 0xbe, 0x5b, 0x0c, 0xdd, 0xfb, 0xc3, 0x57, 0xe7, 0x33, 0x1b, 0x5d, - 0xcc, 0x6c, 0xf4, 0x73, 0x66, 0xa3, 0x8f, 0x73, 0xbb, 0x72, 0x31, 0xb7, 0x2b, 0xdf, 0xe7, 0x76, - 0xe5, 0xf5, 0x41, 0xc0, 0x61, 0x18, 0x7b, 0xc4, 0x97, 0x63, 0xca, 0x45, 0xc0, 0x44, 0xcc, 0x61, - 0xfa, 0xd0, 0x8b, 0xf9, 0x68, 0xb0, 0x54, 0x27, 0xfd, 0xab, 0x92, 0xce, 0xda, 0xdb, 0xd0, 0xaf, - 0xd0, 0xa3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xd9, 0xbc, 0x02, 0xb6, 0x04, 0x00, 0x00, + // 595 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x8e, 0xdd, 0x9f, 0xd0, 0x2d, 0x27, 0xab, 0x45, 0x6e, 0x84, 0x4c, 0x14, 0x28, 0x44, 0x95, + 0xd8, 0x55, 0x42, 0xb9, 0x70, 0xe8, 0xa1, 0x52, 0x29, 0xdc, 0x5a, 0x53, 0x09, 0xc4, 0xa5, 0xb2, + 0x9d, 0xc5, 0x59, 0x91, 0xee, 0x3a, 0xde, 0xb1, 0xb5, 0x11, 0xe2, 0xc2, 0x13, 0x20, 0x78, 0x08, + 0xee, 0x3c, 0x01, 0xc7, 0x1e, 0x2b, 0x71, 0xe1, 0x84, 0x50, 0xc2, 0x83, 0x20, 0xaf, 0x37, 0xa9, + 0x13, 0x24, 0x5a, 0x2e, 0xc9, 0x8e, 0xf7, 0x9b, 0x6f, 0xbe, 0xf9, 0x66, 0x6c, 0xb4, 0x33, 0xcc, + 0x58, 0xf4, 0x56, 0xb2, 0x41, 0x4e, 0x53, 0xc2, 0x38, 0xd0, 0x34, 0xea, 0x07, 0x8c, 0x0f, 0x33, + 0x9a, 0x8e, 0x48, 0xde, 0x21, 0xfa, 0x80, 0x93, 0x54, 0x80, 0x70, 0xbc, 0x0a, 0x16, 0x2f, 0x60, + 0x71, 0xde, 0x69, 0xdc, 0x8d, 0x84, 0x3c, 0x13, 0x92, 0x84, 0x81, 0xa4, 0x24, 0x08, 0x23, 0x46, + 0xf2, 0x4e, 0x48, 0x21, 0xe8, 0xe8, 0xa0, 0x24, 0x69, 0xec, 0x54, 0x41, 0xd3, 0x32, 0x25, 0x2a, + 0x09, 0x62, 0xc6, 0x03, 0x60, 0x82, 0x1b, 0x6c, 0xc3, 0x60, 0x41, 0xcd, 0x30, 0xa0, 0xcc, 0xdd, + 0x46, 0x2c, 0x62, 0xa1, 0x8f, 0xa4, 0x38, 0x99, 0xa7, 0xb7, 0x63, 0x21, 0xe2, 0x01, 0x25, 0x41, + 0xc2, 0x48, 0xc0, 0xb9, 0x00, 0x4d, 0x27, 0xcd, 0x2d, 0x61, 0x61, 0x44, 0x06, 0x2c, 0xee, 0x43, + 0x34, 0x60, 0x94, 0x83, 0x24, 0x40, 0x79, 0x8f, 0xa6, 0x67, 0x8c, 0x43, 0xd1, 0xec, 0x65, 0x64, + 0x12, 0x76, 0xaf, 0x70, 0x67, 0xd1, 0x04, 0x23, 0xa2, 0xc2, 0x0a, 0xa3, 0x84, 0xca, 0xf2, 0xb7, + 0xbc, 0x6d, 0x8d, 0xd0, 0xc6, 0x71, 0x01, 0xf6, 0xe9, 0x30, 0xa3, 0x12, 0xa4, 0xf9, 0x77, 0x9e, + 0x22, 0x74, 0x69, 0x80, 0x6b, 0x35, 0xad, 0xf6, 0x7a, 0xf7, 0x3e, 0x2e, 0x1d, 0xc0, 0x85, 0x5b, + 0x78, 0x6a, 0xb4, 0x76, 0x02, 0x1f, 0x05, 0x31, 0x35, 0xb9, 0x7e, 0x25, 0xd3, 0xd9, 0x42, 0x37, + 0xb4, 0xa2, 0x53, 0xd6, 0x73, 0xed, 0xa6, 0xd5, 0x5e, 0xf3, 0xeb, 0x3a, 0x7e, 0xde, 0x6b, 0x7d, + 0xb1, 0xd0, 0xe6, 0x42, 0x6d, 0x99, 0x08, 0x2e, 0xa9, 0x73, 0x80, 0xea, 0x05, 0x3b, 0xa3, 0xd2, + 0xb5, 0x9a, 0x4b, 0xed, 0xf5, 0xee, 0x36, 0xfe, 0xf7, 0xb0, 0xb1, 0xe6, 0xd9, 0x5f, 0x3e, 0xff, + 0x79, 0xa7, 0xe6, 0x4f, 0x73, 0x9d, 0xc3, 0xb9, 0x1e, 0x6c, 0xdd, 0xc3, 0x83, 0x2b, 0x7b, 0x28, + 0x35, 0x54, 0x9b, 0x68, 0x7d, 0xb2, 0xd1, 0xad, 0x43, 0x0a, 0x27, 0xea, 0x25, 0x83, 0xfe, 0x51, + 0x2a, 0xc4, 0x9b, 0x99, 0xd4, 0x6d, 0x64, 0x83, 0x32, 0xfe, 0x6c, 0x4e, 0xb9, 0x41, 0xcd, 0x38, + 0x4f, 0x94, 0x6f, 0x83, 0x72, 0x0e, 0xd0, 0x3a, 0xa8, 0xd3, 0xd4, 0x64, 0x19, 0x2d, 0xf7, 0xe6, + 0xb4, 0xe8, 0xad, 0xac, 0xa4, 0xcd, 0x84, 0xc0, 0xec, 0xec, 0x10, 0xb4, 0x92, 0x14, 0xe5, 0xdd, + 0x25, 0x4d, 0xb0, 0x85, 0x2b, 0x3b, 0x52, 0x4e, 0xf5, 0x44, 0x95, 0xfa, 0x4a, 0x9c, 0xb3, 0x87, + 0x56, 0xfb, 0x34, 0xe8, 0xd1, 0xd4, 0x5d, 0x36, 0x23, 0x64, 0x61, 0x84, 0xab, 0x4b, 0x57, 0xa5, + 0xc8, 0x3b, 0xf8, 0x99, 0x46, 0xfb, 0x26, 0xab, 0x18, 0x1f, 0xa8, 0xd3, 0x70, 0x04, 0x54, 0xba, + 0x2b, 0x4d, 0xab, 0x7d, 0xd3, 0xaf, 0x83, 0xda, 0x2f, 0xc2, 0xee, 0x37, 0x0b, 0xad, 0x69, 0xdb, + 0x5f, 0xa4, 0x79, 0xea, 0x7c, 0xb5, 0x50, 0xfd, 0xd8, 0xf8, 0xbe, 0x7b, 0xad, 0x69, 0x2d, 0x6c, + 0x5c, 0xe3, 0xf1, 0x7f, 0x66, 0x95, 0x96, 0xb4, 0x9e, 0x7c, 0xf8, 0xfe, 0xfb, 0xb3, 0xbd, 0xeb, + 0x74, 0xc9, 0x35, 0xbe, 0x1d, 0x8c, 0x4a, 0xf2, 0x6e, 0xba, 0x8f, 0xef, 0xf7, 0x5f, 0x9d, 0x8f, + 0x3d, 0xeb, 0x62, 0xec, 0x59, 0xbf, 0xc6, 0x9e, 0xf5, 0x71, 0xe2, 0xd5, 0x2e, 0x26, 0x5e, 0xed, + 0xc7, 0xc4, 0xab, 0xbd, 0xde, 0x8b, 0x19, 0xf4, 0xb3, 0x10, 0x47, 0xe2, 0x8c, 0x30, 0x1e, 0x53, + 0x9e, 0x31, 0x18, 0x3d, 0x0c, 0x33, 0x36, 0xe8, 0xcd, 0xd5, 0x51, 0x7f, 0x55, 0xd2, 0x63, 0x08, + 0x57, 0xf5, 0xdb, 0xf5, 0xe8, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x41, 0xda, 0x1f, 0xc7, 0xd1, + 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -457,6 +468,13 @@ func (m *GetTxWithProofResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) _ = i var l int _ = l + if len(m.TxBytes) > 0 { + i -= len(m.TxBytes) + copy(dAtA[i:], m.TxBytes) + i = encodeVarintQuery(dAtA, i, uint64(len(m.TxBytes))) + i-- + dAtA[i] = 0x2a + } if m.Header != nil { { size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) @@ -577,6 +595,10 @@ func (m *GetTxWithProofResponse) Size() (n int) { l = m.Header.Size() n += 1 + l + sovQuery(uint64(l)) } + l = len(m.TxBytes) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -997,6 +1019,40 @@ func (m *GetTxWithProofResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxBytes = append(m.TxBytes[:0], dAtA[iNdEx:postIndex]...) + if m.TxBytes == nil { + m.TxBytes = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/interchainstaking/keeper/callbacks.go b/x/interchainstaking/keeper/callbacks.go index c3df0e287..78bd049a8 100644 --- a/x/interchainstaking/keeper/callbacks.go +++ b/x/interchainstaking/keeper/callbacks.go @@ -2,20 +2,27 @@ package keeper import ( "bytes" + "encoding/hex" "errors" "fmt" + "strings" "time" sdkioerrors "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/cosmos/cosmos-sdk/types/tx" + "google.golang.org/protobuf/encoding/protowire" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" tmclienttypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" + "github.com/tendermint/tendermint/crypto/tmhash" tmtypes "github.com/tendermint/tendermint/types" "github.com/ingenuity-build/quicksilver/utils" @@ -419,18 +426,37 @@ func DepositTxCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes.Q return err } - _, found = k.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, res.GetTxResponse().TxHash)) + // check tx is valid for hash. + hash := tmhash.Sum(res.Proof.Data) + hashStr := hex.EncodeToString(hash) + + queryRequest := tx.GetTxRequest{} + err = k.cdc.Unmarshal(query.Request, &queryRequest) + if err != nil { + return err + } + + // check hash matches query + if !strings.EqualFold(hashStr, queryRequest.Hash) { + return fmt.Errorf("invalid tx for query - expected %s, got %s", queryRequest.Hash, hashStr) + } + + _, found = k.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hashStr)) if found { - k.Logger(ctx).Debug("Found previously handled tx. Ignoring.", "txhash", res.GetTxResponse().TxHash) + k.Logger(ctx).Info("Found previously handled tx. Ignoring.", "txhash", hashStr) return nil } - err = k.CheckTMHeaderForZone(ctx, &zone, res) + txn, err := TxDecoder(k.cdc)(res.Proof.Data) if err != nil { - return fmt.Errorf("unable to verify proof: %w", err) + return err } - return k.HandleReceiptForTransaction(ctx, res.GetTxResponse(), res.GetTx(), &zone) + txtx, ok := txn.(*tx.Tx) + if !ok { + return errors.New("cannot assert type of tx") + } + return k.HandleReceiptTransaction(ctx, txtx, hashStr, zone) } // AccountBalanceCallback is a callback handler for Balance queries. @@ -567,3 +593,113 @@ func AllBalancesCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes return k.SetAccountBalance(ctx, zone, balanceQuery.Address, args) } + +// TxDecoder +func TxDecoder(cdc codec.Codec) sdk.TxDecoder { + return func(txBytes []byte) (sdk.Tx, error) { + // Make sure txBytes follow ADR-027. + err := rejectNonADR027TxRaw(txBytes) + if err != nil { + return nil, sdkioerrors.Wrap(sdkerrors.ErrTxDecode, err.Error()) + } + + var raw tx.TxRaw + + err = cdc.Unmarshal(txBytes, &raw) + if err != nil { + return nil, err + } + + var body tx.TxBody + + err = cdc.Unmarshal(raw.BodyBytes, &body) + if err != nil { + return nil, sdkioerrors.Wrap(sdkerrors.ErrTxDecode, err.Error()) + } + + var authInfo tx.AuthInfo + + err = cdc.Unmarshal(raw.AuthInfoBytes, &authInfo) + if err != nil { + return nil, sdkioerrors.Wrap(sdkerrors.ErrTxDecode, err.Error()) + } + + return &tx.Tx{ + Body: &body, + AuthInfo: &authInfo, + Signatures: raw.Signatures, + }, nil + } +} + +func rejectNonADR027TxRaw(txBytes []byte) error { + // Make sure all fields are ordered in ascending order with this variable. + prevTagNum := protowire.Number(0) + + for len(txBytes) > 0 { + tagNum, wireType, m := protowire.ConsumeTag(txBytes) + if m < 0 { + return fmt.Errorf("invalid length; %w", protowire.ParseError(m)) + } + // TxRaw only has bytes fields. + if wireType != protowire.BytesType { + return fmt.Errorf("expected %d wire type, got %d", protowire.BytesType, wireType) + } + // Make sure fields are ordered in ascending order. + if tagNum < prevTagNum { + return fmt.Errorf("txRaw must follow ADR-027, got tagNum %d after tagNum %d", tagNum, prevTagNum) + } + prevTagNum = tagNum + + // All 3 fields of TxRaw have wireType == 2, so their next component + // is a varint, so we can safely call ConsumeVarint here. + // Byte structure: + // Inner fields are verified in `DefaultTxDecoder` + lengthPrefix, m := protowire.ConsumeVarint(txBytes[m:]) + if m < 0 { + return fmt.Errorf("invalid length; %w", protowire.ParseError(m)) + } + // We make sure that this varint is as short as possible. + n := varintMinLength(lengthPrefix) + if n != m { + return fmt.Errorf("length prefix varint for tagNum %d is not as short as possible, read %d, only need %d", tagNum, m, n) + } + + // Skip over the bytes that store fieldNumber and wireType bytes. + _, _, m = protowire.ConsumeField(txBytes) + if m < 0 { + return fmt.Errorf("invalid length; %w", protowire.ParseError(m)) + } + txBytes = txBytes[m:] + } + + return nil +} + +// varintMinLength returns the minimum number of bytes necessary to encode an +// uint using varint encoding. +func varintMinLength(n uint64) int { + switch { + // Note: 1< Date: Mon, 29 May 2023 21:36:50 +0100 Subject: [PATCH 02/25] fix delegation flush test --- x/interchainstaking/keeper/delegation.go | 22 ++-- x/interchainstaking/keeper/delegation_test.go | 116 +++++++++++++----- .../keeper/ibc_packet_handlers.go | 4 +- 3 files changed, 103 insertions(+), 39 deletions(-) diff --git a/x/interchainstaking/keeper/delegation.go b/x/interchainstaking/keeper/delegation.go index 3439381c3..4da627232 100644 --- a/x/interchainstaking/keeper/delegation.go +++ b/x/interchainstaking/keeper/delegation.go @@ -280,28 +280,34 @@ func (k *Keeper) MakePerformanceDelegation(ctx sdk.Context, zone *types.Zone, va } func (k *Keeper) FlushOutstandingDelegations(ctx sdk.Context, zone *types.Zone, delAddrBalance sdk.Coin) error { - var amount sdk.Coins + var pendingAmount sdk.Coins exclusionTime := ctx.BlockTime().AddDate(0, 0, -1) - + var coinsToFlush sdk.Coins k.IterateZoneReceipts(ctx, zone, func(_ int64, receiptInfo types.Receipt) (stop bool) { - if receiptInfo.FirstSeen.After(exclusionTime) && receiptInfo.Completed == nil { - amount = amount.Add(receiptInfo.Amount...) + fmt.Println(receiptInfo) + if (receiptInfo.FirstSeen.After(exclusionTime) || receiptInfo.FirstSeen.Equal(exclusionTime)) && receiptInfo.Completed == nil { + pendingAmount = pendingAmount.Add(receiptInfo.Amount...) } return false }) - coins := sdk.NewCoins(delAddrBalance).Sub(amount...) - - if coins.IsAnyNegative() || coins.IsZero() { + var hasNeg bool + coinsToFlush, hasNeg = sdk.NewCoins(delAddrBalance).SafeSub(pendingAmount...) + if hasNeg || coinsToFlush.IsZero() { k.Logger(ctx).Debug("delegate account balance negative, setting outdated reciepts") k.SetReceiptsCompleted(ctx, zone, exclusionTime, ctx.BlockTime()) return nil } + // set the zone amount to the coins to be flushed. + zone.DelegationAddress.Balance = coinsToFlush + k.Logger(ctx).Info("flush delegations ", "total", coinsToFlush) + k.SetZone(ctx, zone) + sendMsg := banktypes.MsgSend{ FromAddress: "", ToAddress: "", - Amount: coins, + Amount: coinsToFlush, } return k.handleSendToDelegate(ctx, zone, &sendMsg, fmt.Sprintf("batch/%d", exclusionTime.Unix())) } diff --git a/x/interchainstaking/keeper/delegation_test.go b/x/interchainstaking/keeper/delegation_test.go index f5af73302..4b19d0661 100644 --- a/x/interchainstaking/keeper/delegation_test.go +++ b/x/interchainstaking/keeper/delegation_test.go @@ -654,7 +654,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { assertStatements func(ctx sdk.Context, quicksilver *app.Quicksilver) bool }{ { - name: "zero pending delegations, no pending receipts, no exclusion receipts", + name: "case 0: zero delegation balance, no pending receipts, no excluded receipts", setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) {}, delAddrBalance: sdk.NewCoin("uatom", sdkmath.ZeroInt()), assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { @@ -662,11 +662,11 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { }, }, { - name: "zero pending delegations, 2 pending receipts and no exclusion receipts", + name: "case 1: zero delegation balance, 2 pending receipts and no excluded receipts", setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) { cutOffTime := ctx.BlockTime().AddDate(0, 0, -1) - rcpt1Time := cutOffTime.Add(-2 * time.Hour) - rcpt2Time := cutOffTime.Add(-3 * time.Hour) + receiptOneTime := cutOffTime.Add(-2 * time.Hour) + receiptTwoTime := cutOffTime.Add(-3 * time.Hour) rcpt1 := types.Receipt{ ChainId: s.chainB.ChainID, @@ -678,7 +678,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { sdk.NewIntFromUint64(2000000), ), ), - FirstSeen: &rcpt1Time, + FirstSeen: &receiptOneTime, Completed: nil, } @@ -692,7 +692,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { sdk.NewIntFromUint64(100), ), ), - FirstSeen: &rcpt2Time, + FirstSeen: &receiptTwoTime, Completed: nil, } quicksilver.InterchainstakingKeeper.SetReceipt(ctx, rcpt1) @@ -716,11 +716,11 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { }, }, { - name: "zero pending delegations, 1 pending receipt and 1 exclusion receipt", + name: "case 2: zero delegation balance, 1 pending receipt and 1 excluded receipt", setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) { cutOffTime := ctx.BlockTime().AddDate(0, 0, -1) - rcpt1Time := cutOffTime.Add(-2 * time.Hour) - rcpt2Time := cutOffTime.Add(2 * time.Hour) + receiptOneTime := cutOffTime.Add(-2 * time.Hour) + receiptTwoTime := cutOffTime.Add(2 * time.Hour) rcpt1 := types.Receipt{ ChainId: s.chainB.ChainID, @@ -732,7 +732,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { sdk.NewIntFromUint64(2000000), ), ), - FirstSeen: &rcpt1Time, + FirstSeen: &receiptOneTime, Completed: nil, } @@ -746,7 +746,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { sdk.NewIntFromUint64(100), ), ), - FirstSeen: &rcpt2Time, + FirstSeen: &receiptTwoTime, } quicksilver.InterchainstakingKeeper.SetReceipt(ctx, rcpt1) quicksilver.InterchainstakingKeeper.SetReceipt(ctx, rcpt2) @@ -767,11 +767,11 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { }, }, { - name: "non-zero pending delegations, 1 pending receipts and 1 exclusion receipts ", + name: "case 3: non-zero delegation balance, 1 pending receipts and 1 excluded receipts ", setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) { - cutOffTime := ctx.BlockTime().AddDate(0, 0, -1) - pendingReceiptTime := cutOffTime.Add(-2 * time.Hour) - excludedReceiptTime := cutOffTime.Add(2 * time.Hour) + cutOffTime := ctx.BlockTime().AddDate(0, 0, -1) // -24h + receiptOneTime := cutOffTime.Add(-2 * time.Hour) // -26h + receiptTwoTime := cutOffTime.Add(2 * time.Hour) // -22h rcpt1 := types.Receipt{ ChainId: s.chainB.ChainID, @@ -783,7 +783,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { sdk.NewIntFromUint64(2000000), ), ), - FirstSeen: &pendingReceiptTime, + FirstSeen: &receiptOneTime, Completed: nil, } @@ -797,7 +797,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { sdk.NewIntFromUint64(100), ), ), - FirstSeen: &excludedReceiptTime, + FirstSeen: &receiptTwoTime, Completed: nil, } quicksilver.InterchainstakingKeeper.SetReceipt(ctx, rcpt1) @@ -821,11 +821,11 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { expectedDelegation: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(2000000))), }, { - name: "non-zero pending delegations, 2 pending receipts", + name: "case 4: non-zero delegation balance, 2 pending receipts", setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) { cutOffTime := ctx.BlockTime().AddDate(0, 0, -1) - rcpt1Time := cutOffTime.Add(-2 * time.Hour) - rcpt2Time := cutOffTime.Add(-3 * time.Hour) + receiptOneTime := cutOffTime.Add(-2 * time.Hour) + receiptTwoTime := cutOffTime.Add(-3 * time.Hour) rcpt1 := types.Receipt{ ChainId: s.chainB.ChainID, @@ -837,7 +837,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { sdk.NewIntFromUint64(2000000), ), ), - FirstSeen: &rcpt1Time, + FirstSeen: &receiptOneTime, Completed: nil, } @@ -851,7 +851,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { sdk.NewIntFromUint64(100), ), ), - FirstSeen: &rcpt2Time, + FirstSeen: &receiptTwoTime, Completed: nil, } quicksilver.InterchainstakingKeeper.SetReceipt(ctx, rcpt1) @@ -872,14 +872,14 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { return true }, mockAck: true, - expectedDelegation: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(2000100))), + expectedDelegation: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(2000000))), }, { - name: "non-zero pending delegations, 2 pending receipts and delegationAccBalance less than total pending", + name: "case 5: zero delegation balance, 1 pending receipt, 1 excluded receipt", setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) { cutOffTime := ctx.BlockTime().AddDate(0, 0, -1) - rcpt1Time := cutOffTime.Add(-2 * time.Hour) - rcpt2Time := cutOffTime.Add(-3 * time.Hour) + receiptOneTime := cutOffTime.Add(-2 * time.Hour) + receiptTwoTime := cutOffTime.Add(2 * time.Hour) rcpt1 := types.Receipt{ ChainId: s.chainB.ChainID, @@ -891,7 +891,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { sdk.NewIntFromUint64(2000000), ), ), - FirstSeen: &rcpt1Time, + FirstSeen: &receiptOneTime, Completed: nil, } @@ -905,7 +905,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { sdk.NewIntFromUint64(100), ), ), - FirstSeen: &rcpt2Time, + FirstSeen: &receiptTwoTime, Completed: nil, } quicksilver.InterchainstakingKeeper.SetReceipt(ctx, rcpt1) @@ -925,8 +925,61 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { s.Require().Equal(0, count) return true }, + // zero delegation balance must mean that we cannot delegate anything. + mockAck: false, + }, + { + name: "case 6: low delegation account balance", + setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) { + cutOffTime := ctx.BlockTime().AddDate(0, 0, -1) + receiptOneTime := cutOffTime.Add(-2 * time.Hour) + rcpt1 := types.Receipt{ + ChainId: s.chainB.ChainID, + Sender: userAddress, + Txhash: "TestDeposit01", + Amount: sdk.NewCoins( + sdk.NewCoin( + denom, + sdk.NewIntFromUint64(2000000), + ), + ), + FirstSeen: &receiptOneTime, + Completed: nil, + } + + rcpt2 := types.Receipt{ + ChainId: s.chainB.ChainID, + Sender: userAddress, + Txhash: "TestDeposit02", + Amount: sdk.NewCoins( + sdk.NewCoin( + denom, + sdk.NewIntFromUint64(100), + ), + ), + FirstSeen: &receiptOneTime, + Completed: nil, + } + quicksilver.InterchainstakingKeeper.SetReceipt(ctx, rcpt1) + quicksilver.InterchainstakingKeeper.SetReceipt(ctx, rcpt2) + }, + delAddrBalance: sdk.NewCoin("uatom", sdkmath.NewInt(100)), + assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { + count := 0 + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + s.Require().True(found) + quicksilver.InterchainstakingKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) { + if receiptInfo.Completed == nil { + count++ + } + return false + }) + s.Require().Equal(0, count) + return true + }, + // delegation balance == 100, which equals the value of the second receipt. mockAck: true, - expectedDelegation: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(2000000))), + expectedDelegation: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(100))), }, } @@ -941,7 +994,10 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { test.setStatements(ctx, quicksilver) zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) s.Require().True(found) + //before := quicksilver.InterchainstakingKeeper.AllReceipts(ctx) err := quicksilver.InterchainstakingKeeper.FlushOutstandingDelegations(ctx, &zone, test.delAddrBalance) + // refetch zone after FlushOutstandingDelegations setZone(). + ctx = s.chainA.GetContext() if test.mockAck { var msgs []sdk.Msg allocations, err := quicksilver.InterchainstakingKeeper.DeterminePlanForDelegation(ctx, &zone, test.expectedDelegation) @@ -952,6 +1008,8 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { s.Require().NoError(err) } } + //after := quicksilver.InterchainstakingKeeper.AllReceipts(ctx) + //fmt.Println(before, after) s.Require().NoError(err) isCorrect := test.assertStatements(ctx, quicksilver) s.Require().True(isCorrect) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers.go b/x/interchainstaking/keeper/ibc_packet_handlers.go index e4c7bd760..5417aa8d0 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers.go @@ -854,8 +854,8 @@ func (k *Keeper) HandleDelegate(ctx sdk.Context, msg sdk.Msg, memo string) error } k.Logger(ctx).Debug("outstanding delegations ack-received") k.SetReceiptsCompleted(ctx, zone, time.Unix(exclusionTimestampUnix, 0), ctx.BlockTime()) - // fmt.Println(zone.DelegationAddress.Balance) - // fmt.Println(delegateMsg.Amount) + fmt.Println(zone.DelegationAddress.Balance) + fmt.Println(delegateMsg.Amount) zone.DelegationAddress.Balance = zone.DelegationAddress.Balance.Sub(delegateMsg.Amount) k.SetZone(ctx, zone) if zone.DelegationAddress.Balance.IsZero() && zone.WithdrawalWaitgroup == 0 { From f59917a25c56e3d9b927ea385e69cb41030aad90 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Tue, 30 May 2023 00:17:14 +0100 Subject: [PATCH 03/25] add tests for HandleDepositTransaction --- x/interchainstaking/keeper/receipt_test.go | 299 +++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100644 x/interchainstaking/keeper/receipt_test.go diff --git a/x/interchainstaking/keeper/receipt_test.go b/x/interchainstaking/keeper/receipt_test.go new file mode 100644 index 000000000..d5006dedc --- /dev/null +++ b/x/interchainstaking/keeper/receipt_test.go @@ -0,0 +1,299 @@ +package keeper_test + +import ( + "time" + + "cosmossdk.io/math" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" + "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" +) + +func (suite *KeeperTestSuite) TestHandleReceiptTransactionGood() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + + msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + + tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + hash := utils.GenerateRandomHashAsHex() + hash2 := utils.GenerateRandomHashAsHex() + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + // rr is 1.0 + err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) + suite.Require().NoError(err) + + after := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, math.NewInt(1000000)), after) + + zone.RedemptionRate = sdk.NewDecWithPrec(12, 1) + err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash2, zone) + suite.Require().NoError(err) + + after2 := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, math.NewInt(1833333)), after2) +} + +func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadRecipient() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + + msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + + tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + hash := utils.GenerateRandomHashAsHex() + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + + err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) + suite.Require().ErrorContains(err, "no sender found. Ignoring") +} + +func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMessageType() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + + msg := stakingtypes.MsgDelegate{DelegatorAddress: fromAddress, ValidatorAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + + tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + hash := utils.GenerateRandomHashAsHex() + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + + err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) + suite.Require().ErrorContains(err, "no sender found. Ignoring") +} + +func (suite *KeeperTestSuite) TestHandleReceiptMixedMessageTypeGood() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + + msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + + msg2 := stakingtypes.MsgDelegate{DelegatorAddress: fromAddress, ValidatorAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000))} + anymsg2, err := codectypes.NewAnyWithValue(&msg2) + suite.Require().NoError(err) + + tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} + hash := utils.GenerateRandomHashAsHex() + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + + err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) + suite.Require().NoError(err) + + after := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, math.NewInt(1000000)), after) +} + +func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMixedSender() { // this shouldn't be possibly in theory, but hey! + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + fromAddress2 := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + + msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + msg2 := banktypes.MsgSend{FromAddress: fromAddress2, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} + anymsg2, err := codectypes.NewAnyWithValue(&msg2) + suite.Require().NoError(err) + + tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} + hash := utils.GenerateRandomHashAsHex() + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + + err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) + suite.Require().ErrorContains(err, "sender mismatch: expected") +} + +func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadDenom() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + + msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin("ushit", math.NewInt(1000000)))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + + tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + hash := utils.GenerateRandomHashAsHex() + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + + err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) + suite.Require().ErrorContains(err, "unable to validate coins. Ignoring") + + after := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), after) +} + +func (suite *KeeperTestSuite) TestMintQAsset() { +} + +// test all getters, setters, deleters, iterators. +func (suite *KeeperTestSuite) TestReceiptStore() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + account1 := utils.GenerateAccAddressForTest() + account2 := utils.GenerateAccAddressForTest() + hash1 := utils.GenerateRandomHashAsHex() + hash2 := utils.GenerateRandomHashAsHex() + hash3 := utils.GenerateRandomHashAsHex() + hash4 := utils.GenerateRandomHashAsHex() + + zone2 := types.Zone{ChainId: "test-1"} + + suite.Require().Zero(len(icsKeeper.AllReceipts(ctx))) + + receipt1 := icsKeeper.NewReceipt(ctx, zone, account1.String(), hash1, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(100)))) + receipt2 := icsKeeper.NewReceipt(ctx, zone, account1.String(), hash2, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(200)))) + receipt3 := icsKeeper.NewReceipt(ctx, zone, account2.String(), hash3, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(300)))) + receipt4 := icsKeeper.NewReceipt(ctx, zone2, account2.String(), hash4, sdk.NewCoins(sdk.NewCoin("uosmo", math.NewInt(500)))) + + icsKeeper.SetReceipt(ctx, *receipt1) + icsKeeper.SetReceipt(ctx, *receipt2) + icsKeeper.SetReceipt(ctx, *receipt3) + icsKeeper.SetReceipt(ctx, *receipt4) + + suite.Require().Equal(4, len(icsKeeper.AllReceipts(ctx))) + + count := 0 + coins := sdk.Coins{} + icsKeeper.IterateReceipts(ctx, func(index int64, receiptInfo types.Receipt) (stop bool) { + count++ + coins = coins.Add(receiptInfo.Amount...) + return false + }) + + suite.Require().Equal(4, count) + suite.Require().Equal(600, int(coins.AmountOf("uatom").Int64())) + suite.Require().Equal(500, int(coins.AmountOf("uosmo").Int64())) + + count = 0 + sum := 0 + icsKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) { + count++ + sum = sum + int(receiptInfo.Amount.AmountOf("uatom").Int64()) + return false + }) + + suite.Require().Equal(3, count) + suite.Require().Equal(600, sum) + + count = 0 + sum = 0 + icsKeeper.IterateZoneReceipts(ctx, &zone2, func(index int64, receiptInfo types.Receipt) (stop bool) { + count++ + sum = sum + int(receiptInfo.Amount.AmountOf("uosmo").Int64()) + return false + }) + + suite.Require().Equal(1, count) + suite.Require().Equal(500, sum) + + out, err := icsKeeper.UserZoneReceipts(ctx, &zone, account1) + suite.Require().NoError(err) + suite.Require().Equal(2, len(out)) + + receipt, found := icsKeeper.GetReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash1)) + suite.Require().True(found) + suite.Require().Equal(receipt1, &receipt) + now := ctx.BlockTime().Add(time.Second) + receipt.Completed = &now + icsKeeper.SetReceipt(ctx, receipt) + icsKeeper.DeleteReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash2)) + + out, err = icsKeeper.UserZoneReceipts(ctx, &zone, account1) + suite.Require().NoError(err) + suite.Require().Equal(1, len(out)) + suite.Require().Equal(&now, out[0].Completed) + + icsKeeper.SetReceiptsCompleted(ctx, &zone, now, now) + + receipt, found = icsKeeper.GetReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash3)) + suite.Require().True(found) + + suite.Require().Equal(&now, receipt.Completed) +} From 263772951cc726be1ee97fe2d8b517864519a819 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Tue, 30 May 2023 10:42:45 +0100 Subject: [PATCH 04/25] update tests for new error handling --- x/interchainstaking/keeper/receipt_test.go | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/x/interchainstaking/keeper/receipt_test.go b/x/interchainstaking/keeper/receipt_test.go index d5006dedc..d775ad4c8 100644 --- a/x/interchainstaking/keeper/receipt_test.go +++ b/x/interchainstaking/keeper/receipt_test.go @@ -76,7 +76,12 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadRecipient() { suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) - suite.Require().ErrorContains(err, "no sender found. Ignoring") + //suite.Require().ErrorContains(err, "no sender found. Ignoring") + nilReceipt, found := icsKeeper.GetReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash)) + suite.Require().True(found) // check nilReceipt is found for hash + suite.Require().Equal("", nilReceipt.Sender) // check nilReceipt has empty sender + suite.Require().Nil(nilReceipt.Amount) // check nilReceipt has nil amount + suite.Require().NoError(err) } func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMessageType() { @@ -103,7 +108,12 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMessageType() { suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) - suite.Require().ErrorContains(err, "no sender found. Ignoring") + //suite.Require().ErrorContains(err, "no sender found. Ignoring") + nilReceipt, found := icsKeeper.GetReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash)) + suite.Require().True(found) // check nilReceipt is found for hash + suite.Require().Equal("", nilReceipt.Sender) // check nilReceipt has empty sender + suite.Require().Nil(nilReceipt.Amount) // check nilReceipt has nil amount + suite.Require().NoError(err) } func (suite *KeeperTestSuite) TestHandleReceiptMixedMessageTypeGood() { @@ -168,7 +178,12 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMixedSender() { // suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) - suite.Require().ErrorContains(err, "sender mismatch: expected") + //suite.Require().ErrorContains(err, "sender mismatch: expected") + nilReceipt, found := icsKeeper.GetReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash)) + suite.Require().True(found) // check nilReceipt is found for hash + suite.Require().Equal("", nilReceipt.Sender) // check nilReceipt has empty sender + suite.Require().Nil(nilReceipt.Amount) // check nilReceipt has nil amount + suite.Require().NoError(err) } func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadDenom() { @@ -201,8 +216,8 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadDenom() { suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), after) } -func (suite *KeeperTestSuite) TestMintQAsset() { -} +// func (suite *KeeperTestSuite) TestMintQAsset() { +// } // test all getters, setters, deleters, iterators. func (suite *KeeperTestSuite) TestReceiptStore() { @@ -227,10 +242,10 @@ func (suite *KeeperTestSuite) TestReceiptStore() { suite.Require().Zero(len(icsKeeper.AllReceipts(ctx))) - receipt1 := icsKeeper.NewReceipt(ctx, zone, account1.String(), hash1, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(100)))) - receipt2 := icsKeeper.NewReceipt(ctx, zone, account1.String(), hash2, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(200)))) - receipt3 := icsKeeper.NewReceipt(ctx, zone, account2.String(), hash3, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(300)))) - receipt4 := icsKeeper.NewReceipt(ctx, zone2, account2.String(), hash4, sdk.NewCoins(sdk.NewCoin("uosmo", math.NewInt(500)))) + receipt1 := icsKeeper.NewReceipt(ctx, &zone, account1.String(), hash1, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(100)))) + receipt2 := icsKeeper.NewReceipt(ctx, &zone, account1.String(), hash2, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(200)))) + receipt3 := icsKeeper.NewReceipt(ctx, &zone, account2.String(), hash3, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(300)))) + receipt4 := icsKeeper.NewReceipt(ctx, &zone2, account2.String(), hash4, sdk.NewCoins(sdk.NewCoin("uosmo", math.NewInt(500)))) icsKeeper.SetReceipt(ctx, *receipt1) icsKeeper.SetReceipt(ctx, *receipt2) From cd44c382e07387b4e2cd8f6b9fd135fcd19b2850 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Fri, 2 Jun 2023 15:06:39 +0100 Subject: [PATCH 05/25] remove superflous field in proto --- proto/quicksilver/interchainquery/v1/query.proto | 2 -- 1 file changed, 2 deletions(-) diff --git a/proto/quicksilver/interchainquery/v1/query.proto b/proto/quicksilver/interchainquery/v1/query.proto index adf51853c..e98d14055 100644 --- a/proto/quicksilver/interchainquery/v1/query.proto +++ b/proto/quicksilver/interchainquery/v1/query.proto @@ -45,6 +45,4 @@ message GetTxWithProofResponse { tendermint.types.TxProof proof = 3; // ibc-go header to validate txs ibc.lightclients.tendermint.v1.Header header = 4; - // tx_bytes is the byte representation of the queried tx - bytes tx_bytes = 5; } From f9a1f711df35e11bfaf7fb00b5bfacaaa5230d90 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Fri, 2 Jun 2023 16:05:33 +0100 Subject: [PATCH 06/25] final v1.2.13 front-port and test fixes --- docs/swagger.yml | 20 ++- x/interchainquery/types/query.pb.go | 130 +++++------------- x/interchainstaking/keeper/callbacks.go | 6 +- x/interchainstaking/keeper/delegation.go | 2 +- x/interchainstaking/keeper/delegation_test.go | 10 +- .../keeper/ibc_packet_handlers.go | 2 +- x/interchainstaking/keeper/receipt.go | 7 +- x/interchainstaking/keeper/receipt_test.go | 49 ++++--- x/interchainstaking/types/keys.go | 3 +- x/interchainstaking/types/redemptions.go | 4 - 10 files changed, 83 insertions(+), 150 deletions(-) diff --git a/docs/swagger.yml b/docs/swagger.yml index bdf552730..32d1f848e 100644 --- a/docs/swagger.yml +++ b/docs/swagger.yml @@ -1688,12 +1688,8 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } - // or ... - if (any.isSameTypeAs(Foo.getDefaultInstance())) { - foo = any.unpack(Foo.getDefaultInstance()); - } - Example 3: Pack and unpack a message in Python. + Example 3: Pack and unpack a message in Python. foo = Foo(...) any = Any() @@ -1703,7 +1699,7 @@ paths: any.Unpack(foo) ... - Example 4: Pack and unpack a message in Go + Example 4: Pack and unpack a message in Go foo := &pb.Foo{...} any, err := anypb.New(foo) @@ -1731,8 +1727,10 @@ paths: name "y.z". + JSON + ==== The JSON representation of an `Any` value uses the regular @@ -2001,12 +1999,8 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } - // or ... - if (any.isSameTypeAs(Foo.getDefaultInstance())) { - foo = any.unpack(Foo.getDefaultInstance()); - } - Example 3: Pack and unpack a message in Python. + Example 3: Pack and unpack a message in Python. foo = Foo(...) any = Any() @@ -2016,7 +2010,7 @@ paths: any.Unpack(foo) ... - Example 4: Pack and unpack a message in Go + Example 4: Pack and unpack a message in Go foo := &pb.Foo{...} any, err := anypb.New(foo) @@ -2044,8 +2038,10 @@ paths: name "y.z". + JSON + ==== The JSON representation of an `Any` value uses the regular diff --git a/x/interchainquery/types/query.pb.go b/x/interchainquery/types/query.pb.go index 0e1dd423a..1f3f16b6f 100644 --- a/x/interchainquery/types/query.pb.go +++ b/x/interchainquery/types/query.pb.go @@ -151,8 +151,6 @@ type GetTxWithProofResponse struct { Proof *types1.TxProof `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"` // ibc-go header to validate txs Header *types2.Header `protobuf:"bytes,4,opt,name=header,proto3" json:"header,omitempty"` - // tx_bytes is the byte representation of the queried tx - TxBytes []byte `protobuf:"bytes,5,opt,name=tx_bytes,json=txBytes,proto3" json:"tx_bytes,omitempty"` } func (m *GetTxWithProofResponse) Reset() { *m = GetTxWithProofResponse{} } @@ -216,13 +214,6 @@ func (m *GetTxWithProofResponse) GetHeader() *types2.Header { return nil } -func (m *GetTxWithProofResponse) GetTxBytes() []byte { - if m != nil { - return m.TxBytes - } - return nil -} - func init() { proto.RegisterType((*QueryRequestsRequest)(nil), "quicksilver.interchainquery.v1.QueryRequestsRequest") proto.RegisterType((*QueryRequestsResponse)(nil), "quicksilver.interchainquery.v1.QueryRequestsResponse") @@ -234,45 +225,43 @@ func init() { } var fileDescriptor_e4aadfdae61bcbb1 = []byte{ - // 595 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0x8e, 0xdd, 0x9f, 0xd0, 0x2d, 0x27, 0xab, 0x45, 0x6e, 0x84, 0x4c, 0x14, 0x28, 0x44, 0x95, - 0xd8, 0x55, 0x42, 0xb9, 0x70, 0xe8, 0xa1, 0x52, 0x29, 0xdc, 0x5a, 0x53, 0x09, 0xc4, 0xa5, 0xb2, - 0x9d, 0xc5, 0x59, 0x91, 0xee, 0x3a, 0xde, 0xb1, 0xb5, 0x11, 0xe2, 0xc2, 0x13, 0x20, 0x78, 0x08, - 0xee, 0x3c, 0x01, 0xc7, 0x1e, 0x2b, 0x71, 0xe1, 0x84, 0x50, 0xc2, 0x83, 0x20, 0xaf, 0x37, 0xa9, - 0x13, 0x24, 0x5a, 0x2e, 0xc9, 0x8e, 0xf7, 0x9b, 0x6f, 0xbe, 0xf9, 0x66, 0x6c, 0xb4, 0x33, 0xcc, - 0x58, 0xf4, 0x56, 0xb2, 0x41, 0x4e, 0x53, 0xc2, 0x38, 0xd0, 0x34, 0xea, 0x07, 0x8c, 0x0f, 0x33, - 0x9a, 0x8e, 0x48, 0xde, 0x21, 0xfa, 0x80, 0x93, 0x54, 0x80, 0x70, 0xbc, 0x0a, 0x16, 0x2f, 0x60, - 0x71, 0xde, 0x69, 0xdc, 0x8d, 0x84, 0x3c, 0x13, 0x92, 0x84, 0x81, 0xa4, 0x24, 0x08, 0x23, 0x46, - 0xf2, 0x4e, 0x48, 0x21, 0xe8, 0xe8, 0xa0, 0x24, 0x69, 0xec, 0x54, 0x41, 0xd3, 0x32, 0x25, 0x2a, - 0x09, 0x62, 0xc6, 0x03, 0x60, 0x82, 0x1b, 0x6c, 0xc3, 0x60, 0x41, 0xcd, 0x30, 0xa0, 0xcc, 0xdd, - 0x46, 0x2c, 0x62, 0xa1, 0x8f, 0xa4, 0x38, 0x99, 0xa7, 0xb7, 0x63, 0x21, 0xe2, 0x01, 0x25, 0x41, - 0xc2, 0x48, 0xc0, 0xb9, 0x00, 0x4d, 0x27, 0xcd, 0x2d, 0x61, 0x61, 0x44, 0x06, 0x2c, 0xee, 0x43, - 0x34, 0x60, 0x94, 0x83, 0x24, 0x40, 0x79, 0x8f, 0xa6, 0x67, 0x8c, 0x43, 0xd1, 0xec, 0x65, 0x64, - 0x12, 0x76, 0xaf, 0x70, 0x67, 0xd1, 0x04, 0x23, 0xa2, 0xc2, 0x0a, 0xa3, 0x84, 0xca, 0xf2, 0xb7, - 0xbc, 0x6d, 0x8d, 0xd0, 0xc6, 0x71, 0x01, 0xf6, 0xe9, 0x30, 0xa3, 0x12, 0xa4, 0xf9, 0x77, 0x9e, - 0x22, 0x74, 0x69, 0x80, 0x6b, 0x35, 0xad, 0xf6, 0x7a, 0xf7, 0x3e, 0x2e, 0x1d, 0xc0, 0x85, 0x5b, - 0x78, 0x6a, 0xb4, 0x76, 0x02, 0x1f, 0x05, 0x31, 0x35, 0xb9, 0x7e, 0x25, 0xd3, 0xd9, 0x42, 0x37, - 0xb4, 0xa2, 0x53, 0xd6, 0x73, 0xed, 0xa6, 0xd5, 0x5e, 0xf3, 0xeb, 0x3a, 0x7e, 0xde, 0x6b, 0x7d, - 0xb1, 0xd0, 0xe6, 0x42, 0x6d, 0x99, 0x08, 0x2e, 0xa9, 0x73, 0x80, 0xea, 0x05, 0x3b, 0xa3, 0xd2, - 0xb5, 0x9a, 0x4b, 0xed, 0xf5, 0xee, 0x36, 0xfe, 0xf7, 0xb0, 0xb1, 0xe6, 0xd9, 0x5f, 0x3e, 0xff, - 0x79, 0xa7, 0xe6, 0x4f, 0x73, 0x9d, 0xc3, 0xb9, 0x1e, 0x6c, 0xdd, 0xc3, 0x83, 0x2b, 0x7b, 0x28, - 0x35, 0x54, 0x9b, 0x68, 0x7d, 0xb2, 0xd1, 0xad, 0x43, 0x0a, 0x27, 0xea, 0x25, 0x83, 0xfe, 0x51, - 0x2a, 0xc4, 0x9b, 0x99, 0xd4, 0x6d, 0x64, 0x83, 0x32, 0xfe, 0x6c, 0x4e, 0xb9, 0x41, 0xcd, 0x38, - 0x4f, 0x94, 0x6f, 0x83, 0x72, 0x0e, 0xd0, 0x3a, 0xa8, 0xd3, 0xd4, 0x64, 0x19, 0x2d, 0xf7, 0xe6, - 0xb4, 0xe8, 0xad, 0xac, 0xa4, 0xcd, 0x84, 0xc0, 0xec, 0xec, 0x10, 0xb4, 0x92, 0x14, 0xe5, 0xdd, - 0x25, 0x4d, 0xb0, 0x85, 0x2b, 0x3b, 0x52, 0x4e, 0xf5, 0x44, 0x95, 0xfa, 0x4a, 0x9c, 0xb3, 0x87, - 0x56, 0xfb, 0x34, 0xe8, 0xd1, 0xd4, 0x5d, 0x36, 0x23, 0x64, 0x61, 0x84, 0xab, 0x4b, 0x57, 0xa5, - 0xc8, 0x3b, 0xf8, 0x99, 0x46, 0xfb, 0x26, 0xab, 0x18, 0x1f, 0xa8, 0xd3, 0x70, 0x04, 0x54, 0xba, - 0x2b, 0x4d, 0xab, 0x7d, 0xd3, 0xaf, 0x83, 0xda, 0x2f, 0xc2, 0xee, 0x37, 0x0b, 0xad, 0x69, 0xdb, - 0x5f, 0xa4, 0x79, 0xea, 0x7c, 0xb5, 0x50, 0xfd, 0xd8, 0xf8, 0xbe, 0x7b, 0xad, 0x69, 0x2d, 0x6c, - 0x5c, 0xe3, 0xf1, 0x7f, 0x66, 0x95, 0x96, 0xb4, 0x9e, 0x7c, 0xf8, 0xfe, 0xfb, 0xb3, 0xbd, 0xeb, - 0x74, 0xc9, 0x35, 0xbe, 0x1d, 0x8c, 0x4a, 0xf2, 0x6e, 0xba, 0x8f, 0xef, 0xf7, 0x5f, 0x9d, 0x8f, - 0x3d, 0xeb, 0x62, 0xec, 0x59, 0xbf, 0xc6, 0x9e, 0xf5, 0x71, 0xe2, 0xd5, 0x2e, 0x26, 0x5e, 0xed, - 0xc7, 0xc4, 0xab, 0xbd, 0xde, 0x8b, 0x19, 0xf4, 0xb3, 0x10, 0x47, 0xe2, 0x8c, 0x30, 0x1e, 0x53, - 0x9e, 0x31, 0x18, 0x3d, 0x0c, 0x33, 0x36, 0xe8, 0xcd, 0xd5, 0x51, 0x7f, 0x55, 0xd2, 0x63, 0x08, - 0x57, 0xf5, 0xdb, 0xf5, 0xe8, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x41, 0xda, 0x1f, 0xc7, 0xd1, - 0x04, 0x00, 0x00, + // 576 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x41, 0x6f, 0xd3, 0x30, + 0x18, 0xad, 0xbb, 0xb1, 0x31, 0xf7, 0x16, 0x6d, 0xa8, 0xab, 0x50, 0xa8, 0x0a, 0x83, 0x6a, 0x12, + 0xb6, 0x5a, 0xca, 0x85, 0xc3, 0x0e, 0x93, 0xc6, 0xe0, 0xb6, 0x85, 0x4a, 0x20, 0x2e, 0x53, 0x92, + 0x9a, 0xd4, 0xa2, 0xb5, 0xd3, 0xf8, 0x4b, 0x94, 0x0a, 0x71, 0xe1, 0x17, 0x20, 0xf1, 0x23, 0xb8, + 0xf3, 0x0b, 0x38, 0xee, 0x38, 0x89, 0x0b, 0x27, 0x84, 0x5a, 0xfe, 0x03, 0x57, 0x14, 0xc7, 0xcd, + 0xd2, 0x22, 0xb1, 0x71, 0x69, 0xed, 0xf8, 0xbd, 0xf7, 0xbd, 0xef, 0xf9, 0x4b, 0xf0, 0xfe, 0x24, + 0xe6, 0xfe, 0x5b, 0xc5, 0x47, 0x09, 0x8b, 0x28, 0x17, 0xc0, 0x22, 0x7f, 0xe8, 0x72, 0x31, 0x89, + 0x59, 0x34, 0xa5, 0x49, 0x87, 0xea, 0x05, 0x09, 0x23, 0x09, 0xd2, 0xb2, 0x4b, 0x58, 0xb2, 0x82, + 0x25, 0x49, 0xa7, 0x71, 0xd7, 0x97, 0x6a, 0x2c, 0x15, 0xf5, 0x5c, 0xc5, 0xa8, 0xeb, 0xf9, 0x9c, + 0x26, 0x1d, 0x8f, 0x81, 0xdb, 0xd1, 0x9b, 0x5c, 0xa4, 0xb1, 0x5f, 0x06, 0x2d, 0xca, 0xe4, 0xa8, + 0xd0, 0x0d, 0xb8, 0x70, 0x81, 0x4b, 0x61, 0xb0, 0x0d, 0x83, 0x85, 0xb4, 0xc0, 0x40, 0x6a, 0xce, + 0xb6, 0x03, 0x19, 0x48, 0xbd, 0xa4, 0xd9, 0xca, 0x3c, 0xbd, 0x1d, 0x48, 0x19, 0x8c, 0x18, 0x75, + 0x43, 0x4e, 0x5d, 0x21, 0x24, 0x68, 0x39, 0x65, 0x4e, 0x29, 0xf7, 0x7c, 0x3a, 0xe2, 0xc1, 0x10, + 0xfc, 0x11, 0x67, 0x02, 0x14, 0x05, 0x26, 0x06, 0x2c, 0x1a, 0x73, 0x01, 0x59, 0xb3, 0x97, 0x3b, + 0x43, 0xe8, 0x5d, 0x91, 0xce, 0x6a, 0x08, 0xc6, 0x44, 0x49, 0x15, 0xa6, 0x21, 0x53, 0xf9, 0x6f, + 0x7e, 0xda, 0x9a, 0xe2, 0xed, 0xd3, 0x0c, 0xec, 0xb0, 0x49, 0xcc, 0x14, 0x28, 0xf3, 0x6f, 0x3d, + 0xc5, 0xf8, 0x32, 0x80, 0x3a, 0x6a, 0xa2, 0x76, 0xad, 0x7b, 0x9f, 0xe4, 0x09, 0x90, 0x2c, 0x2d, + 0xb2, 0x08, 0x5a, 0x27, 0x41, 0x4e, 0xdc, 0x80, 0x19, 0xae, 0x53, 0x62, 0x5a, 0xbb, 0xf8, 0xa6, + 0x76, 0x74, 0xc6, 0x07, 0xf5, 0x6a, 0x13, 0xb5, 0xb7, 0x9c, 0x4d, 0xbd, 0x7f, 0x3e, 0x68, 0x7d, + 0x46, 0x78, 0x67, 0xa5, 0xb6, 0x0a, 0xa5, 0x50, 0xcc, 0x3a, 0xc2, 0x9b, 0x99, 0x3a, 0x67, 0xaa, + 0x8e, 0x9a, 0x6b, 0xed, 0x5a, 0x77, 0x8f, 0xfc, 0xfb, 0xb2, 0x89, 0xd6, 0x39, 0x5c, 0x3f, 0xff, + 0x71, 0xa7, 0xe2, 0x2c, 0xb8, 0xd6, 0xf1, 0x52, 0x0f, 0x55, 0xdd, 0xc3, 0x83, 0x2b, 0x7b, 0xc8, + 0x3d, 0x94, 0x9b, 0x68, 0xfd, 0x46, 0xf8, 0xd6, 0x31, 0x83, 0x7e, 0xfa, 0x92, 0xc3, 0xf0, 0x24, + 0x92, 0xf2, 0x4d, 0x61, 0x75, 0x0f, 0x57, 0x21, 0x35, 0xf9, 0xec, 0x2c, 0xb4, 0x21, 0x2d, 0x34, + 0xfb, 0xa9, 0x53, 0x85, 0xd4, 0x3a, 0xc2, 0x35, 0x48, 0xcf, 0x22, 0xc3, 0x32, 0x5e, 0xee, 0x2d, + 0x79, 0xd1, 0x53, 0x59, 0xa2, 0x15, 0x46, 0xa0, 0x58, 0x5b, 0x14, 0xdf, 0x08, 0xb3, 0xf2, 0xf5, + 0x35, 0x2d, 0xb0, 0x4b, 0x4a, 0x33, 0x92, 0xdf, 0x6a, 0x3f, 0xcd, 0xfd, 0xe5, 0x38, 0xeb, 0x00, + 0x6f, 0x0c, 0x99, 0x3b, 0x60, 0x51, 0x7d, 0xdd, 0x5c, 0x21, 0xf7, 0x7c, 0x52, 0x1e, 0xba, 0xb2, + 0x44, 0xd2, 0x21, 0xcf, 0x34, 0xda, 0x31, 0xac, 0xee, 0x57, 0x84, 0xb7, 0x74, 0xb6, 0x2f, 0xa2, + 0x24, 0xb2, 0xbe, 0x20, 0xbc, 0x79, 0x6a, 0xc2, 0xed, 0x5d, 0xeb, 0x4a, 0x56, 0xc6, 0xaa, 0xf1, + 0xf8, 0x3f, 0x59, 0x79, 0xdf, 0xad, 0x27, 0x1f, 0xbe, 0xfd, 0xfa, 0x54, 0xed, 0x59, 0x5d, 0x7a, + 0x8d, 0x0f, 0x04, 0x67, 0x8a, 0xbe, 0x5b, 0x0c, 0xdd, 0xfb, 0xc3, 0x57, 0xe7, 0x33, 0x1b, 0x5d, + 0xcc, 0x6c, 0xf4, 0x73, 0x66, 0xa3, 0x8f, 0x73, 0xbb, 0x72, 0x31, 0xb7, 0x2b, 0xdf, 0xe7, 0x76, + 0xe5, 0xf5, 0x41, 0xc0, 0x61, 0x18, 0x7b, 0xc4, 0x97, 0x63, 0xca, 0x45, 0xc0, 0x44, 0xcc, 0x61, + 0xfa, 0xd0, 0x8b, 0xf9, 0x68, 0xb0, 0x54, 0x27, 0xfd, 0xab, 0x92, 0xce, 0xda, 0xdb, 0xd0, 0xaf, + 0xd0, 0xa3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xd9, 0xbc, 0x02, 0xb6, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -468,13 +457,6 @@ func (m *GetTxWithProofResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) _ = i var l int _ = l - if len(m.TxBytes) > 0 { - i -= len(m.TxBytes) - copy(dAtA[i:], m.TxBytes) - i = encodeVarintQuery(dAtA, i, uint64(len(m.TxBytes))) - i-- - dAtA[i] = 0x2a - } if m.Header != nil { { size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) @@ -595,10 +577,6 @@ func (m *GetTxWithProofResponse) Size() (n int) { l = m.Header.Size() n += 1 + l + sovQuery(uint64(l)) } - l = len(m.TxBytes) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } return n } @@ -1019,40 +997,6 @@ func (m *GetTxWithProofResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TxBytes", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TxBytes = append(m.TxBytes[:0], dAtA[iNdEx:postIndex]...) - if m.TxBytes == nil { - m.TxBytes = []byte{} - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/interchainstaking/keeper/callbacks.go b/x/interchainstaking/keeper/callbacks.go index 78bd049a8..c9b423c79 100644 --- a/x/interchainstaking/keeper/callbacks.go +++ b/x/interchainstaking/keeper/callbacks.go @@ -447,7 +447,7 @@ func DepositTxCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes.Q return nil } - txn, err := TxDecoder(k.cdc)(res.Proof.Data) + txn, err := txDecoder(k.cdc)(res.Proof.Data) if err != nil { return err } @@ -594,8 +594,8 @@ func AllBalancesCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes return k.SetAccountBalance(ctx, zone, balanceQuery.Address, args) } -// TxDecoder -func TxDecoder(cdc codec.Codec) sdk.TxDecoder { +// txDecoder. +func txDecoder(cdc codec.Codec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { // Make sure txBytes follow ADR-027. err := rejectNonADR027TxRaw(txBytes) diff --git a/x/interchainstaking/keeper/delegation.go b/x/interchainstaking/keeper/delegation.go index 4da627232..d747330c2 100644 --- a/x/interchainstaking/keeper/delegation.go +++ b/x/interchainstaking/keeper/delegation.go @@ -284,7 +284,6 @@ func (k *Keeper) FlushOutstandingDelegations(ctx sdk.Context, zone *types.Zone, exclusionTime := ctx.BlockTime().AddDate(0, 0, -1) var coinsToFlush sdk.Coins k.IterateZoneReceipts(ctx, zone, func(_ int64, receiptInfo types.Receipt) (stop bool) { - fmt.Println(receiptInfo) if (receiptInfo.FirstSeen.After(exclusionTime) || receiptInfo.FirstSeen.Equal(exclusionTime)) && receiptInfo.Completed == nil { pendingAmount = pendingAmount.Add(receiptInfo.Amount...) } @@ -292,6 +291,7 @@ func (k *Keeper) FlushOutstandingDelegations(ctx sdk.Context, zone *types.Zone, }) var hasNeg bool + coinsToFlush, hasNeg = sdk.NewCoins(delAddrBalance).SafeSub(pendingAmount...) if hasNeg || coinsToFlush.IsZero() { k.Logger(ctx).Debug("delegate account balance negative, setting outdated reciepts") diff --git a/x/interchainstaking/keeper/delegation_test.go b/x/interchainstaking/keeper/delegation_test.go index 4b19d0661..e28d7d7df 100644 --- a/x/interchainstaking/keeper/delegation_test.go +++ b/x/interchainstaking/keeper/delegation_test.go @@ -911,7 +911,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { quicksilver.InterchainstakingKeeper.SetReceipt(ctx, rcpt1) quicksilver.InterchainstakingKeeper.SetReceipt(ctx, rcpt2) }, - delAddrBalance: sdk.NewCoin("uatom", sdkmath.NewInt(2000000)), + delAddrBalance: sdk.NewCoin("uatom", sdkmath.NewInt(0)), assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { count := 0 zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) @@ -922,7 +922,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { } return false }) - s.Require().Equal(0, count) + s.Require().Equal(1, count) return true }, // zero delegation balance must mean that we cannot delegate anything. @@ -994,7 +994,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { test.setStatements(ctx, quicksilver) zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) s.Require().True(found) - //before := quicksilver.InterchainstakingKeeper.AllReceipts(ctx) + // before := quicksilver.InterchainstakingKeeper.AllReceipts(ctx) err := quicksilver.InterchainstakingKeeper.FlushOutstandingDelegations(ctx, &zone, test.delAddrBalance) // refetch zone after FlushOutstandingDelegations setZone(). ctx = s.chainA.GetContext() @@ -1008,8 +1008,8 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { s.Require().NoError(err) } } - //after := quicksilver.InterchainstakingKeeper.AllReceipts(ctx) - //fmt.Println(before, after) + // after := quicksilver.InterchainstakingKeeper.AllReceipts(ctx) + // fmt.Println(before, after) s.Require().NoError(err) isCorrect := test.assertStatements(ctx, quicksilver) s.Require().True(isCorrect) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers.go b/x/interchainstaking/keeper/ibc_packet_handlers.go index 5417aa8d0..be6ea353f 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers.go @@ -860,7 +860,7 @@ func (k *Keeper) HandleDelegate(ctx sdk.Context, msg sdk.Msg, memo string) error k.SetZone(ctx, zone) if zone.DelegationAddress.Balance.IsZero() && zone.WithdrawalWaitgroup == 0 { k.Logger(ctx).Info("Triggering redemption rate calc after delegation flush") - if err = k.TriggerRedemptionRate(ctx, zone); err != nil { + if err := k.TriggerRedemptionRate(ctx, zone); err != nil { return err } } diff --git a/x/interchainstaking/keeper/receipt.go b/x/interchainstaking/keeper/receipt.go index d93994fe8..e178e23c2 100644 --- a/x/interchainstaking/keeper/receipt.go +++ b/x/interchainstaking/keeper/receipt.go @@ -3,7 +3,6 @@ package keeper import ( "errors" "fmt" - "strings" "time" sdkioerrors "cosmossdk.io/errors" @@ -63,6 +62,7 @@ func (k Keeper) HandleReceiptTransaction(ctx sdk.Context, txn *tx.Tx, txHash str if senderAddress == Unset { k.Logger(ctx).Error("no sender found. Ignoring.") + fmt.Println("HERE1") k.NilReceipt(ctx, &zone, hash) // nil receipt will stop this hash being submitted again return nil } @@ -302,6 +302,7 @@ func (k *Keeper) SubmitTx(ctx sdk.Context, msgs []sdk.Msg, account *types.ICAAcc func (k Keeper) NilReceipt(ctx sdk.Context, zone *types.Zone, txhash string) { t := ctx.BlockTime() r := types.Receipt{ChainId: zone.ChainId, Sender: "", Txhash: txhash, Amount: sdk.Coins{}, FirstSeen: &t, Completed: &t} + fmt.Println(r) k.SetReceipt(ctx, r) } @@ -410,7 +411,3 @@ func (k *Keeper) SetReceiptsCompleted(ctx sdk.Context, zone *types.Zone, qualify return false }) } - -func GetReceiptKey(chainID, txhash string) string { - return fmt.Sprintf("%s/%s", chainID, strings.ToUpper(txhash)) -} diff --git a/x/interchainstaking/keeper/receipt_test.go b/x/interchainstaking/keeper/receipt_test.go index d775ad4c8..9778bca62 100644 --- a/x/interchainstaking/keeper/receipt_test.go +++ b/x/interchainstaking/keeper/receipt_test.go @@ -10,7 +10,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ingenuity-build/quicksilver/utils" - "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -31,21 +30,21 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionGood() { anymsg, err := codectypes.NewAnyWithValue(&msg) suite.Require().NoError(err) - tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} hash := utils.GenerateRandomHashAsHex() hash2 := utils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) // rr is 1.0 - err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) suite.Require().NoError(err) after := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, math.NewInt(1000000)), after) zone.RedemptionRate = sdk.NewDecWithPrec(12, 1) - err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash2, zone) + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash2, zone) suite.Require().NoError(err) after2 := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) @@ -69,15 +68,15 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadRecipient() { anymsg, err := codectypes.NewAnyWithValue(&msg) suite.Require().NoError(err) - tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} hash := utils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) - err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) - //suite.Require().ErrorContains(err, "no sender found. Ignoring") - nilReceipt, found := icsKeeper.GetReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash)) + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) + // suite.Require().ErrorContains(err, "no sender found. Ignoring") + nilReceipt, found := icsKeeper.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash)) suite.Require().True(found) // check nilReceipt is found for hash suite.Require().Equal("", nilReceipt.Sender) // check nilReceipt has empty sender suite.Require().Nil(nilReceipt.Amount) // check nilReceipt has nil amount @@ -101,15 +100,15 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMessageType() { anymsg, err := codectypes.NewAnyWithValue(&msg) suite.Require().NoError(err) - tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} hash := utils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) - err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) - //suite.Require().ErrorContains(err, "no sender found. Ignoring") - nilReceipt, found := icsKeeper.GetReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash)) + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) + // suite.Require().ErrorContains(err, "no sender found. Ignoring") + nilReceipt, found := icsKeeper.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash)) suite.Require().True(found) // check nilReceipt is found for hash suite.Require().Equal("", nilReceipt.Sender) // check nilReceipt has empty sender suite.Require().Nil(nilReceipt.Amount) // check nilReceipt has nil amount @@ -137,13 +136,13 @@ func (suite *KeeperTestSuite) TestHandleReceiptMixedMessageTypeGood() { anymsg2, err := codectypes.NewAnyWithValue(&msg2) suite.Require().NoError(err) - tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} hash := utils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) - err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) suite.Require().NoError(err) after := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) @@ -171,15 +170,15 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMixedSender() { // anymsg2, err := codectypes.NewAnyWithValue(&msg2) suite.Require().NoError(err) - tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} hash := utils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) - err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) - //suite.Require().ErrorContains(err, "sender mismatch: expected") - nilReceipt, found := icsKeeper.GetReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash)) + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) + // suite.Require().ErrorContains(err, "sender mismatch: expected") + nilReceipt, found := icsKeeper.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash)) suite.Require().True(found) // check nilReceipt is found for hash suite.Require().Equal("", nilReceipt.Sender) // check nilReceipt has empty sender suite.Require().Nil(nilReceipt.Amount) // check nilReceipt has nil amount @@ -203,13 +202,13 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadDenom() { anymsg, err := codectypes.NewAnyWithValue(&msg) suite.Require().NoError(err) - tx := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} hash := utils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) - err = icsKeeper.HandleReceiptTransaction(ctx, tx, hash, zone) + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) suite.Require().ErrorContains(err, "unable to validate coins. Ignoring") after := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) @@ -270,7 +269,7 @@ func (suite *KeeperTestSuite) TestReceiptStore() { sum := 0 icsKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) { count++ - sum = sum + int(receiptInfo.Amount.AmountOf("uatom").Int64()) + sum += int(receiptInfo.Amount.AmountOf("uatom").Int64()) return false }) @@ -281,7 +280,7 @@ func (suite *KeeperTestSuite) TestReceiptStore() { sum = 0 icsKeeper.IterateZoneReceipts(ctx, &zone2, func(index int64, receiptInfo types.Receipt) (stop bool) { count++ - sum = sum + int(receiptInfo.Amount.AmountOf("uosmo").Int64()) + sum += int(receiptInfo.Amount.AmountOf("uosmo").Int64()) return false }) @@ -292,13 +291,13 @@ func (suite *KeeperTestSuite) TestReceiptStore() { suite.Require().NoError(err) suite.Require().Equal(2, len(out)) - receipt, found := icsKeeper.GetReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash1)) + receipt, found := icsKeeper.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash1)) suite.Require().True(found) suite.Require().Equal(receipt1, &receipt) now := ctx.BlockTime().Add(time.Second) receipt.Completed = &now icsKeeper.SetReceipt(ctx, receipt) - icsKeeper.DeleteReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash2)) + icsKeeper.DeleteReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash2)) out, err = icsKeeper.UserZoneReceipts(ctx, &zone, account1) suite.Require().NoError(err) @@ -307,7 +306,7 @@ func (suite *KeeperTestSuite) TestReceiptStore() { icsKeeper.SetReceiptsCompleted(ctx, &zone, now, now) - receipt, found = icsKeeper.GetReceipt(ctx, keeper.GetReceiptKey(zone.ChainId, hash3)) + receipt, found = icsKeeper.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash3)) suite.Require().True(found) suite.Require().Equal(&now, receipt.Completed) diff --git a/x/interchainstaking/types/keys.go b/x/interchainstaking/types/keys.go index 0e9e355a1..9e544e580 100644 --- a/x/interchainstaking/types/keys.go +++ b/x/interchainstaking/types/keys.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "errors" "fmt" + "strings" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -122,7 +123,7 @@ func GetPerformanceDelegationsKey(zone *Zone, delAddr sdk.AccAddress) []byte { } func GetReceiptKey(chainID, txhash string) string { - return fmt.Sprintf("%s/%s", chainID, txhash) + return fmt.Sprintf("%s/%s", chainID, strings.ToUpper(txhash)) } // GetRedelegationKey gets the redelegation key. diff --git a/x/interchainstaking/types/redemptions.go b/x/interchainstaking/types/redemptions.go index 711c2ec5a..573ec5945 100644 --- a/x/interchainstaking/types/redemptions.go +++ b/x/interchainstaking/types/redemptions.go @@ -1,8 +1,6 @@ package types import ( - "fmt" - "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -34,7 +32,6 @@ func DetermineAllocationsForUndelegation(currentAllocations map[string]math.Int, if !deltas[idx].Weight.IsNegative() { continue } - fmt.Println("trying to remove from overallocated", deltas[idx].ValoperAddress) outWeights[deltas[idx].ValoperAddress] = deltas[idx].Weight.Quo(sdk.NewDecFromInt(sum)).Mul(sdk.NewDecFromInt(overAllocationSplit)).TruncateInt().Abs() if outWeights[deltas[idx].ValoperAddress].GT(availablePerValidator[deltas[idx].ValoperAddress]) { outWeights[deltas[idx].ValoperAddress] = availablePerValidator[deltas[idx].ValoperAddress] @@ -42,7 +39,6 @@ func DetermineAllocationsForUndelegation(currentAllocations map[string]math.Int, } else { availablePerValidator[deltas[idx].ValoperAddress] = availablePerValidator[deltas[idx].ValoperAddress].Sub(outWeights[deltas[idx].ValoperAddress]) } - fmt.Println("removed from overallocated", outWeights[deltas[idx].ValoperAddress]) deltas[idx].Weight = deltas[idx].Weight.Add(sdk.NewDecFromInt(outWeights[deltas[idx].ValoperAddress])) outSum = outSum.Add(outWeights[deltas[idx].ValoperAddress]) From c8f02053a875550e57949834bd9350d5b4e43107 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Fri, 2 Jun 2023 16:23:32 +0100 Subject: [PATCH 07/25] s/s/suite/ --- x/interchainstaking/keeper/callbacks_test.go | 901 ++++++++---------- x/interchainstaking/keeper/delegation_test.go | 563 ++--------- x/interchainstaking/keeper/fuzz_test.go | 10 +- x/interchainstaking/keeper/grpc_query_test.go | 306 +++--- .../keeper/ibc_packet_handlers_test.go | 358 ++++--- x/interchainstaking/keeper/intent_test.go | 78 +- x/interchainstaking/keeper/keeper_test.go | 238 ++--- x/interchainstaking/keeper/msg_server_test.go | 254 ++--- .../keeper/redelegation_record_test.go | 24 +- x/interchainstaking/keeper/validator_test.go | 28 +- 10 files changed, 1129 insertions(+), 1631 deletions(-) diff --git a/x/interchainstaking/keeper/callbacks_test.go b/x/interchainstaking/keeper/callbacks_test.go index 8e6b31928..f7e093535 100644 --- a/x/interchainstaking/keeper/callbacks_test.go +++ b/x/interchainstaking/keeper/callbacks_test.go @@ -29,7 +29,7 @@ const ( storeStakingKey = "store/staking/key" ) -func (s *KeeperTestSuite) TestHandleValsetCallback() { +func (suite *KeeperTestSuite) TestHandleValsetCallback() { newVal := utils.GenerateValAddressForTest() tests := []struct { @@ -229,150 +229,129 @@ func (s *KeeperTestSuite) TestHandleValsetCallback() { } for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(test.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - chainBVals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetValidators(s.chainB.GetContext(), 300) + chainBVals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetValidators(suite.chainB.GetContext(), 300) queryResp := test.valset(chainBVals) bz, err := quicksilver.AppCodec().Marshal(&queryResp) - s.Require().NoError(err) + suite.Require().NoError(err) - err = keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: s.chainB.ChainID}) - s.Require().NoError(err) + err = keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: suite.chainB.ChainID}) + suite.Require().NoError(err) // valset callback doesn't actually update validators, but does emit icq callbacks. - test.checks(s.Require(), ctx, quicksilver, chainBVals) + test.checks(suite.Require(), ctx, quicksilver, chainBVals) }) } } -func (s *KeeperTestSuite) TestHandleValsetCallbackBadChain() { - s.Run("bad chain", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestHandleValsetCallbackBadChain() { + suite.Run("bad chain", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() queryResp := stakingtypes.QueryValidatorsResponse{Validators: []stakingtypes.Validator{}} bz, err := quicksilver.AppCodec().Marshal(&queryResp) - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: "badchain"}) // this should bail on a non-matching chain id. - s.Require().Error(err) + suite.Require().Error(err) }) } -func (s *KeeperTestSuite) TestHandleValsetCallbackNilValset() { - s.Run("nil valset", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestHandleValsetCallbackNilValset() { + suite.Run("nil valset", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() queryResp := stakingtypes.QueryValidatorsResponse{Validators: []stakingtypes.Validator{}} bz, err := quicksilver.AppCodec().Marshal(&queryResp) - s.Require().NoError(err) + suite.Require().NoError(err) - err = keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: s.chainB.ChainID}) + err = keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: suite.chainB.ChainID}) // this should error on unmarshalling an empty slice, which is not a valid response here. - s.Require().Error(err) + suite.Require().Error(err) }) } -func (s *KeeperTestSuite) TestHandleValsetCallbackInvalidResponse() { - s.Run("bad payload type", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestHandleValsetCallbackInvalidResponse() { + suite.Run("bad payload type", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() queryReq := stakingtypes.QueryValidatorsRequest{Status: stakingtypes.BondStatusBonded} bz, err := quicksilver.AppCodec().Marshal(&queryReq) - s.Require().NoError(err) + suite.Require().NoError(err) - err = keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: s.chainB.ChainID}) + err = keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: suite.chainB.ChainID}) // this should error on unmarshalling an empty slice, which is not a valid response here. - s.Require().Error(err) + suite.Require().Error(err) }) } -// ValidatorCallback +func (suite *KeeperTestSuite) TestHandleValidatorCallbackBadChain() { + suite.Run("bad chain", func() { + suite.SetupTest() + suite.setupTestZones() -// func (s *KeeperTestSuite) TestHandleValidatorCallbackInvalidResponse() { -// s.Run("bad payload type", func() { -// s.SetupTest() -// s.SetupZones() - -// app := s.GetQuicksilverApp(s.chainA) -// quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() -// ctx := s.chainA.GetContext() - -// query := stakingtypes.QueryValidatorsRequest{Status: stakingtypes.BondStatusBonded} -// bz, err := quicksilver.AppCodec().Marshal(&query) -// s.Require().NoError(err) - -// err = keeper.ValidatorCallback(quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainID: s.chainB.ChainID}) -// // this should error on unmarshalling an empty slice, which is not a valid response here. -// s.Require().Error(err) -// }) -// } - -func (s *KeeperTestSuite) TestHandleValidatorCallbackBadChain() { - s.Run("bad chain", func() { - s.SetupTest() - s.setupTestZones() - - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() queryResp := stakingtypes.QueryValidatorsResponse{Validators: []stakingtypes.Validator{}} bz, err := quicksilver.AppCodec().Marshal(&queryResp) - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.ValidatorCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: "badchain"}) // this should bail on a non-matching chain id. - s.Require().Error(err) + suite.Require().Error(err) }) } -func (s *KeeperTestSuite) TestHandleValidatorCallbackNilValue() { - s.Run("empty value", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestHandleValidatorCallbackNilValue() { + suite.Run("empty value", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() bz := []byte{} - err := keeper.ValidatorCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: s.chainB.ChainID}) + err := keeper.ValidatorCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: suite.chainB.ChainID}) // this should error on unmarshalling an empty slice, which is not a valid response here. - s.Require().Error(err) + suite.Require().Error(err) }) } -func (s *KeeperTestSuite) TestHandleValidatorCallback() { +func (suite *KeeperTestSuite) TestHandleValidatorCallback() { newVal := utils.GenerateAccAddressForTestWithPrefix("cosmosvaloper") zone := icstypes.Zone{ConnectionId: "connection-0", ChainId: "cosmoshub-4", AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom", Is_118: true} - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetValidator(s.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetValidator(s.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper156gqf9837u7d4c4678yt3rl4ls9c5vuursrrzf", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetValidator(s.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper14lultfckehtszvzw4ehu0apvsr77afvyju5zzy", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetValidator(s.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper1a3yjj7d3qnx4spgvjcwjq9cw9snrrrhu5h6jll", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetValidator(s.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper1z8zjv3lntpwxua0rtpvgrcwl0nm0tltgpgs6l7", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetValidator(suite.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetValidator(suite.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper156gqf9837u7d4c4678yt3rl4ls9c5vuursrrzf", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetValidator(suite.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper14lultfckehtszvzw4ehu0apvsr77afvyju5zzy", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetValidator(suite.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper1a3yjj7d3qnx4spgvjcwjq9cw9snrrrhu5h6jll", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetValidator(suite.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper1z8zjv3lntpwxua0rtpvgrcwl0nm0tltgpgs6l7", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) tests := []struct { name string @@ -402,35 +381,35 @@ func (s *KeeperTestSuite) TestHandleValidatorCallback() { } for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(test.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) bz, err := quicksilver.AppCodec().Marshal(&test.validator) - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.ValidatorCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: zone.ChainId}) - s.Require().NoError(err) + suite.Require().NoError(err) zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, zone.ChainId) - s.True(found) + suite.True(found) valAddrBytes, err := utils.ValAddressFromBech32(test.expected.ValoperAddress, zone.GetValoperPrefix()) - s.Require().NoError(err) + suite.Require().NoError(err) val, found := quicksilver.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) - s.True(found) - s.Equal(test.expected, val) + suite.True(found) + suite.Equal(test.expected, val) }) } } -func (s *KeeperTestSuite) TestHandleValidatorCallbackJailedWithSlashing() { +func (suite *KeeperTestSuite) TestHandleValidatorCallbackJailedWithSlashing() { completion := time.Now().UTC().Add(time.Hour) tests := []struct { @@ -454,7 +433,7 @@ func (s *KeeperTestSuite) TestHandleValidatorCallbackJailedWithSlashing() { withdrawal: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) icstypes.WithdrawalRecord { vals := qs.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) return icstypes.WithdrawalRecord{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: zone.DelegationAddress.Address, Distribution: []*icstypes.Distribution{ { @@ -473,7 +452,7 @@ func (s *KeeperTestSuite) TestHandleValidatorCallbackJailedWithSlashing() { expectedWithdrawal: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) icstypes.WithdrawalRecord { vals := qs.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) return icstypes.WithdrawalRecord{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: zone.DelegationAddress.Address, Distribution: []*icstypes.Distribution{ { @@ -504,7 +483,7 @@ func (s *KeeperTestSuite) TestHandleValidatorCallbackJailedWithSlashing() { withdrawal: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) icstypes.WithdrawalRecord { vals := qs.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) return icstypes.WithdrawalRecord{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: zone.DelegationAddress.Address, Distribution: []*icstypes.Distribution{ { @@ -527,7 +506,7 @@ func (s *KeeperTestSuite) TestHandleValidatorCallbackJailedWithSlashing() { expectedWithdrawal: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) icstypes.WithdrawalRecord { vals := qs.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) return icstypes.WithdrawalRecord{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: zone.DelegationAddress.Address, Distribution: []*icstypes.Distribution{ { @@ -562,7 +541,7 @@ func (s *KeeperTestSuite) TestHandleValidatorCallbackJailedWithSlashing() { withdrawal: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) icstypes.WithdrawalRecord { vals := qs.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) return icstypes.WithdrawalRecord{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: zone.DelegationAddress.Address, Distribution: []*icstypes.Distribution{ { @@ -585,7 +564,7 @@ func (s *KeeperTestSuite) TestHandleValidatorCallbackJailedWithSlashing() { expectedWithdrawal: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) icstypes.WithdrawalRecord { vals := qs.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) return icstypes.WithdrawalRecord{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: zone.DelegationAddress.Address, Distribution: []*icstypes.Distribution{ { @@ -609,140 +588,80 @@ func (s *KeeperTestSuite) TestHandleValidatorCallbackJailedWithSlashing() { } for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(test.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) quicksilver.InterchainstakingKeeper.SetWithdrawalRecord(ctx, test.withdrawal(ctx, quicksilver, zone)) bz, err := quicksilver.AppCodec().Marshal(test.validator(ctx, quicksilver, zone)) - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.ValidatorCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: zone.ChainId}) - s.Require().NoError(err) + suite.Require().NoError(err) - wr, found := quicksilver.InterchainstakingKeeper.GetWithdrawalRecord(ctx, s.chainB.ChainID, test.withdrawal(ctx, quicksilver, zone).Txhash, test.withdrawal(ctx, quicksilver, zone).Status) - s.True(found) - s.Require().Equal(test.expectedWithdrawal(ctx, quicksilver, zone), wr) + wr, found := quicksilver.InterchainstakingKeeper.GetWithdrawalRecord(ctx, suite.chainB.ChainID, test.withdrawal(ctx, quicksilver, zone).Txhash, test.withdrawal(ctx, quicksilver, zone).Status) + suite.True(found) + suite.Require().Equal(test.expectedWithdrawal(ctx, quicksilver, zone), wr) }) } } -// func (s *KeeperTestSuite) TestHandleDelegationCallback() { -// type TestCase struct { -// name string -// setup func(vals []*types.Validator) []types.Delegation -// callback func(vals []*types.Validator) stakingtypes.Delegation -// expected func(vals []*types.Validator) types.Delegation -// } - -// tests := []TestCase{ -// func() TestCase { -// d1 := utils.GenerateValAddressForTest() -// return TestCase{ -// name: "valid - no-op", -// setup: func(vals []*types.Validator) []types.Delegation { -// return []types.Delegation{ -// {DelegationAddress: d1.String(), ValidatorAddress: vals[0].ValoperAddress, Amount: sdk.NewCoin("uatom", sdk.NewInt(5000000))}, -// {DelegationAddress: d1.String(), ValidatorAddress: vals[1].ValoperAddress, Amount: sdk.NewCoin("raa", sdk.NewInt(2000000))}, -// } -// }, -// callback: func(vals []*types.Validator) stakingtypes.Delegation { -// return stakingtypes.Delegation{DelegatorAddress: d1.String(), ValidatorAddress: vals[0].ValoperAddress, Shares: sdk.NewDec(1000)} -// }, -// expected: func(vals []*types.Validator) types.Delegation { -// return types.Delegation{DelegationAddress: d1.String(), ValidatorAddress: vals[0].ValoperAddress} -// }, -// } -// }(), -// } - -// for _, test := range tests { -// s.Run(test.name, func() { -// s.SetupTest() -// s.SetupZones() - -// app := s.GetQuicksilverApp(s.chainA) -// quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() -// ctx := s.chainA.GetContext() - -// zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) -// s.Require().True(found) - -// for _, dg := range test.setup(zone.Validators) { -// quicksilver.InterchainstakingKeeper.SetDelegation(ctx, &zone, dg) -// } - -// payload := test.callback(zone.Validators) -// bz, err := quicksilver.AppCodec().Marshal(&payload) -// s.Require().NoError(err) - -// err = keeper.DelegationCallback(quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainID: s.chainB.ChainID}) -// s.Require().NoError(err) - -// expected := test.expected(zone.Validators) -// fmt.Println(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone)) -// _, found = quicksilver.InterchainstakingKeeper.GetDelegation(ctx, &zone, expected.DelegationAddress, expected.ValidatorAddress) -// s.Require().True(found) -// }) -// } -// } - -func (s *KeeperTestSuite) TestHandleRewardsCallbackBadChain() { - s.Run("bad chain", func() { - s.SetupTest() - s.setupTestZones() - - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) TestHandleRewardsCallbackBadChain() { + suite.Run("bad chain", func() { + suite.SetupTest() + suite.setupTestZones() + + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() queryRes := distrtypes.QueryDelegationTotalRewardsResponse{} bz, err := quicksilver.AppCodec().Marshal(&queryRes) - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.RewardsCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: "badchain"}) // this should bail on a non-matching chain id. - s.Require().Error(err) + suite.Require().Error(err) }) } -func (s *KeeperTestSuite) TestHandleRewardsEmptyRequestCallback() { - s.Run("empty request", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestHandleRewardsEmptyRequestCallback() { + suite.Run("empty request", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() queryReq := distrtypes.QueryDelegationTotalRewardsRequest{} bz, err := quicksilver.AppCodec().Marshal(&queryReq) - s.Require().NoError(err) + suite.Require().NoError(err) - err = keeper.RewardsCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: s.chainB.ChainID}) + err = keeper.RewardsCallback(&quicksilver.InterchainstakingKeeper, ctx, bz, icqtypes.Query{ChainId: suite.chainB.ChainID}) // this should fail because the waitgroup becomes negative. - s.Require().Errorf(err, "attempted to unmarshal zero length byte slice (2)") + suite.Require().Errorf(err, "attempted to unmarshal zero length byte slice (2)") }) } -func (s *KeeperTestSuite) TestHandleRewardsCallbackNonDelegator() { - s.Run("valid response, bad delegator", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestHandleRewardsCallbackNonDelegator() { + suite.Run("valid response, bad delegator", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.WithdrawalWaitgroup++ quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) @@ -754,31 +673,31 @@ func (s *KeeperTestSuite) TestHandleRewardsCallbackNonDelegator() { response := distrtypes.QueryDelegationTotalRewardsResponse{ Rewards: []distrtypes.DelegationDelegatorReward{ - {ValidatorAddress: s.chainB.Vals.Validators[0].String(), Reward: sdk.NewDecCoins(sdk.NewDecCoin("uatom", sdk.NewInt((1000))))}, + {ValidatorAddress: suite.chainB.Vals.Validators[0].String(), Reward: sdk.NewDecCoins(sdk.NewDecCoin("uatom", sdk.NewInt((1000))))}, }, Total: sdk.NewDecCoins(sdk.NewDecCoin("uatom", sdk.NewInt((1000)))), } reqbz, err := quicksilver.AppCodec().Marshal(&queryReq) - s.Require().NoError(err) + suite.Require().NoError(err) respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) - err = keeper.RewardsCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: reqbz}) + suite.Require().NoError(err) + err = keeper.RewardsCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: reqbz}) // - s.Require().Errorf(err, "failed attempting to withdraw rewards from non-delegation account") + suite.Require().Errorf(err, "failed attempting to withdraw rewards from non-delegation account") }) } -func (s *KeeperTestSuite) TestHandleRewardsCallbackEmptyResponse() { - s.Run("empty response", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestHandleRewardsCallbackEmptyResponse() { + suite.Run("empty response", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.WithdrawalWaitgroup++ quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) @@ -788,26 +707,26 @@ func (s *KeeperTestSuite) TestHandleRewardsCallbackEmptyResponse() { response := distrtypes.QueryDelegationTotalRewardsResponse{} reqbz, err := quicksilver.AppCodec().Marshal(&queryReq) - s.Require().NoError(err) + suite.Require().NoError(err) respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) - err = keeper.RewardsCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: reqbz}) + suite.Require().NoError(err) + err = keeper.RewardsCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: reqbz}) // - s.Require().NoError(err) + suite.Require().NoError(err) }) } -func (s *KeeperTestSuite) TestHandleValideRewardsCallback() { - s.Run("valid response, negative waitgroup", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestHandleValideRewardsCallback() { + suite.Run("valid response, negative waitgroup", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.WithdrawalWaitgroup++ quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) @@ -817,51 +736,51 @@ func (s *KeeperTestSuite) TestHandleValideRewardsCallback() { response := distrtypes.QueryDelegationTotalRewardsResponse{ Rewards: []distrtypes.DelegationDelegatorReward{ - {ValidatorAddress: s.chainB.Vals.Validators[0].String(), Reward: sdk.NewDecCoins(sdk.NewDecCoin("uatom", sdk.NewInt((1000))))}, + {ValidatorAddress: suite.chainB.Vals.Validators[0].String(), Reward: sdk.NewDecCoins(sdk.NewDecCoin("uatom", sdk.NewInt((1000))))}, }, Total: sdk.NewDecCoins(sdk.NewDecCoin("uatom", sdk.NewInt((1000)))), } reqbz, err := quicksilver.AppCodec().Marshal(&queryReq) - s.Require().NoError(err) + suite.Require().NoError(err) respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) - err = keeper.RewardsCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: reqbz}) + suite.Require().NoError(err) + err = keeper.RewardsCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: reqbz}) // - s.Require().NoError(err) + suite.Require().NoError(err) }) } -func (s *KeeperTestSuite) TestAllBalancesCallback() { - s.Run("all balances non-zero)", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestAllBalancesCallback() { + suite.Run("all balances non-zero)", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) queryReq := banktypes.QueryAllBalancesRequest{ Address: zone.DepositAddress.Address, } reqbz, err := quicksilver.AppCodec().Marshal(&queryReq) - s.Require().NoError(err) + suite.Require().NoError(err) response := banktypes.QueryAllBalancesResponse{Balances: sdk.NewCoins(sdk.NewCoin("uqck", sdk.OneInt()))} respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) + suite.Require().NoError(err) - err = keeper.AllBalancesCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: reqbz}) - s.Require().NoError(err) + err = keeper.AllBalancesCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: reqbz}) + suite.Require().NoError(err) // refetch zone - zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().Equal(uint32(1), zone.DepositAddress.BalanceWaitgroup) + zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().Equal(uint32(1), zone.DepositAddress.BalanceWaitgroup) _, addr, err := bech32.DecodeAndConvert(zone.DepositAddress.Address) - s.Require().NoError(err) + suite.Require().NoError(err) data := banktypes.CreateAccountBalancesPrefix(addr) // check a ICQ request was made @@ -876,20 +795,20 @@ func (s *KeeperTestSuite) TestAllBalancesCallback() { } return false }) - s.Require().True(found) + suite.Require().True(found) }) } -func (s *KeeperTestSuite) TestAllBalancesCallbackWithExistingWg() { - s.Run("all balances non-zero)", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestAllBalancesCallbackWithExistingWg() { + suite.Run("all balances non-zero)", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.DepositAddress.BalanceWaitgroup = 2 quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) @@ -897,21 +816,21 @@ func (s *KeeperTestSuite) TestAllBalancesCallbackWithExistingWg() { Address: zone.DepositAddress.Address, } reqbz, err := quicksilver.AppCodec().Marshal(&queryReq) - s.Require().NoError(err) + suite.Require().NoError(err) response := banktypes.QueryAllBalancesResponse{Balances: sdk.NewCoins(sdk.NewCoin("uqck", sdk.OneInt()))} respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) + suite.Require().NoError(err) - err = keeper.AllBalancesCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: reqbz}) - s.Require().NoError(err) + err = keeper.AllBalancesCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: reqbz}) + suite.Require().NoError(err) // refetch zone - zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().Equal(uint32(1), zone.DepositAddress.BalanceWaitgroup) + zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().Equal(uint32(1), zone.DepositAddress.BalanceWaitgroup) _, addr, err := bech32.DecodeAndConvert(zone.DepositAddress.Address) - s.Require().NoError(err) + suite.Require().NoError(err) data := banktypes.CreateAccountBalancesPrefix(addr) // check a ICQ request was made @@ -926,23 +845,23 @@ func (s *KeeperTestSuite) TestAllBalancesCallbackWithExistingWg() { } return false }) - s.Require().True(found) + suite.Require().True(found) }) } // tests where we have an existing balance and that balance is now reported as zero. // we expect that an icq query will be emitted to assert with proof that the balance // is now zero. -func (s *KeeperTestSuite) TestAllBalancesCallbackExistingBalanceNowNil() { - s.Run("existing balance - now zero - deposit", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestAllBalancesCallbackExistingBalanceNowNil() { + suite.Run("existing balance - now zero - deposit", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.DepositAddress.Balance = sdk.NewCoins(sdk.NewCoin("uqck", sdk.OneInt())) quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) @@ -950,21 +869,21 @@ func (s *KeeperTestSuite) TestAllBalancesCallbackExistingBalanceNowNil() { Address: zone.DepositAddress.Address, } reqbz, err := quicksilver.AppCodec().Marshal(&queryReq) - s.Require().NoError(err) + suite.Require().NoError(err) response := banktypes.QueryAllBalancesResponse{Balances: sdk.Coins{}} respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) + suite.Require().NoError(err) - err = keeper.AllBalancesCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: reqbz}) - s.Require().NoError(err) + err = keeper.AllBalancesCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: reqbz}) + suite.Require().NoError(err) // refetch zone - zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().Equal(uint32(1), zone.DepositAddress.BalanceWaitgroup) + zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().Equal(uint32(1), zone.DepositAddress.BalanceWaitgroup) _, addr, err := bech32.DecodeAndConvert(zone.DepositAddress.Address) - s.Require().NoError(err) + suite.Require().NoError(err) data := banktypes.CreateAccountBalancesPrefix(addr) // check a ICQ request was made @@ -979,18 +898,18 @@ func (s *KeeperTestSuite) TestAllBalancesCallbackExistingBalanceNowNil() { } return false }) - s.Require().True(found) + suite.Require().True(found) }) - s.Run("existing balance - now zero - withdrawal", func() { - s.SetupTest() - s.setupTestZones() + suite.Run("existing balance - now zero - withdrawal", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.WithdrawalAddress.Balance = sdk.NewCoins(sdk.NewCoin("uqck", sdk.OneInt())) quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) @@ -998,21 +917,21 @@ func (s *KeeperTestSuite) TestAllBalancesCallbackExistingBalanceNowNil() { Address: zone.WithdrawalAddress.Address, } reqbz, err := quicksilver.AppCodec().Marshal(&queryReq) - s.Require().NoError(err) + suite.Require().NoError(err) response := banktypes.QueryAllBalancesResponse{Balances: sdk.Coins{}} respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) + suite.Require().NoError(err) - err = keeper.AllBalancesCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: reqbz}) - s.Require().NoError(err) + err = keeper.AllBalancesCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: reqbz}) + suite.Require().NoError(err) // refetch zone - zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().Equal(uint32(1), zone.WithdrawalAddress.BalanceWaitgroup) + zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().Equal(uint32(1), zone.WithdrawalAddress.BalanceWaitgroup) _, addr, err := bech32.DecodeAndConvert(zone.WithdrawalAddress.Address) - s.Require().NoError(err) + suite.Require().NoError(err) data := banktypes.CreateAccountBalancesPrefix(addr) // check a ICQ request was made @@ -1027,40 +946,40 @@ func (s *KeeperTestSuite) TestAllBalancesCallbackExistingBalanceNowNil() { } return false }) - s.Require().True(found) + suite.Require().True(found) }) } -func (s *KeeperTestSuite) TestAllBalancesCallbackMulti() { - s.Run("all balances non-zero)", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestAllBalancesCallbackMulti() { + suite.Run("all balances non-zero)", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) queryReq := banktypes.QueryAllBalancesRequest{ Address: zone.DepositAddress.Address, } reqbz, err := quicksilver.AppCodec().Marshal(&queryReq) - s.Require().NoError(err) + suite.Require().NoError(err) response := banktypes.QueryAllBalancesResponse{Balances: sdk.NewCoins(sdk.NewCoin("uqck", sdk.OneInt()), sdk.NewCoin("stake", sdk.OneInt()))} respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) + suite.Require().NoError(err) - err = keeper.AllBalancesCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: reqbz}) - s.Require().NoError(err) + err = keeper.AllBalancesCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: reqbz}) + suite.Require().NoError(err) // refetch zone - zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().Equal(uint32(2), zone.DepositAddress.BalanceWaitgroup) + zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().Equal(uint32(2), zone.DepositAddress.BalanceWaitgroup) _, addr, err := bech32.DecodeAndConvert(zone.DepositAddress.Address) - s.Require().NoError(err) + suite.Require().NoError(err) data := banktypes.CreateAccountBalancesPrefix(addr) // check a ICQ request was made for each denom @@ -1076,50 +995,50 @@ func (s *KeeperTestSuite) TestAllBalancesCallbackMulti() { } return false }) - s.Require().True(found) + suite.Require().True(found) } }) } -func (s *KeeperTestSuite) TestAccountBalanceCallback() { - s.Run("account balance", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestAccountBalanceCallback() { + suite.Run("account balance", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.DepositAddress.IncrementBalanceWaitgroup() zone.WithdrawalAddress.IncrementBalanceWaitgroup() quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) response := sdk.NewCoin("qck", sdk.NewInt(10)) respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) + suite.Require().NoError(err) for _, addr := range []string{zone.DepositAddress.Address, zone.WithdrawalAddress.Address} { accAddr, err := sdk.AccAddressFromBech32(addr) - s.Require().NoError(err) + suite.Require().NoError(err) data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("qck")...) - err = keeper.AccountBalanceCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: data}) - s.Require().NoError(err) + err = keeper.AccountBalanceCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) + suite.Require().NoError(err) } }) } -func (s *KeeperTestSuite) TestAccountBalance046Callback() { - s.Run("account balance", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestAccountBalance046Callback() { + suite.Run("account balance", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.DepositAddress.IncrementBalanceWaitgroup() zone.WithdrawalAddress.IncrementBalanceWaitgroup() quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) @@ -1127,73 +1046,73 @@ func (s *KeeperTestSuite) TestAccountBalance046Callback() { response := sdk.NewInt(10) respbz, err := response.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) for _, addr := range []string{zone.DepositAddress.Address, zone.WithdrawalAddress.Address} { accAddr, err := sdk.AccAddressFromBech32(addr) - s.Require().NoError(err) + suite.Require().NoError(err) data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("qck")...) - err = keeper.AccountBalanceCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: data}) - s.Require().NoError(err) + err = keeper.AccountBalanceCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) + suite.Require().NoError(err) } }) } -func (s *KeeperTestSuite) TestAccountBalanceCallbackMismatch() { - s.Run("account balance", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestAccountBalanceCallbackMismatch() { + suite.Run("account balance", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.DepositAddress.IncrementBalanceWaitgroup() zone.WithdrawalAddress.IncrementBalanceWaitgroup() quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) response := sdk.NewCoin("qck", sdk.NewInt(10)) respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) + suite.Require().NoError(err) for _, addr := range []string{zone.DepositAddress.Address, zone.WithdrawalAddress.Address} { accAddr, err := sdk.AccAddressFromBech32(addr) - s.Require().NoError(err) + suite.Require().NoError(err) data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("stake")...) - err = keeper.AccountBalanceCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: data}) - s.Require().ErrorContains(err, "received coin denom qck does not match requested denom stake") + err = keeper.AccountBalanceCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) + suite.Require().ErrorContains(err, "received coin denom qck does not match requested denom stake") } }) } -func (s *KeeperTestSuite) TestAccountBalanceCallbackNil() { - s.Run("account balance", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestAccountBalanceCallbackNil() { + suite.Run("account balance", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.DepositAddress.IncrementBalanceWaitgroup() zone.WithdrawalAddress.IncrementBalanceWaitgroup() quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) var response *sdk.Coin respbz, err := quicksilver.AppCodec().Marshal(response) - s.Require().NoError(err) + suite.Require().NoError(err) for _, addr := range []string{zone.DepositAddress.Address, zone.WithdrawalAddress.Address} { accAddr, err := sdk.AccAddressFromBech32(addr) - s.Require().NoError(err) + suite.Require().NoError(err) data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("stake")...) - err = keeper.AccountBalanceCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: data}) - s.Require().NoError(err) + err = keeper.AccountBalanceCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) + suite.Require().NoError(err) } }) } @@ -1201,34 +1120,34 @@ func (s *KeeperTestSuite) TestAccountBalanceCallbackNil() { // Ensures that a fuzz vector which resulted in a crash of ValidatorReq.Pagination crashing // doesn't creep back up. Please see https://github.com/ingenuity-build/quicksilver-incognito/issues/82 func TestValsetCallbackNilValidatorReqPagination(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() data := []byte("\x12\"\n 00000000000000000000000000000000") - _ = keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID}) + _ = keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID}) } func TestDelegationsCallbackAllPresentNoChange(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() cdc := quicksilver.IBCKeeper.Codec() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -1248,9 +1167,9 @@ func TestDelegationsCallbackAllPresentNoChange(t *testing.T) { delegationQuery := stakingtypes.QueryDelegatorDelegationsRequest{DelegatorAddr: zone.DelegationAddress.Address, Pagination: &query.PageRequest{Limit: uint64(len(zone.Validators))}} bz := cdc.MustMarshal(&delegationQuery) - err := keeper.DelegationsCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID, Request: bz}) + err := keeper.DelegationsCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: bz}) - s.Require().NoError(err) + suite.Require().NoError(err) delegationRequests := 0 for _, query := range quicksilver.InterchainQueryKeeper.AllQueries(ctx) { @@ -1259,25 +1178,25 @@ func TestDelegationsCallbackAllPresentNoChange(t *testing.T) { } } - s.Require().Equal(0, delegationRequests) - s.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) + suite.Require().Equal(0, delegationRequests) + suite.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) } func TestDelegationsCallbackAllPresentOneChange(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() cdc := quicksilver.IBCKeeper.Codec() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -1297,9 +1216,9 @@ func TestDelegationsCallbackAllPresentOneChange(t *testing.T) { delegationQuery := stakingtypes.QueryDelegatorDelegationsRequest{DelegatorAddr: zone.DelegationAddress.Address, Pagination: &query.PageRequest{Limit: uint64(len(zone.Validators))}} bz := cdc.MustMarshal(&delegationQuery) - err := keeper.DelegationsCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID, Request: bz}) + err := keeper.DelegationsCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: bz}) - s.Require().NoError(err) + suite.Require().NoError(err) delegationRequests := 0 for _, query := range quicksilver.InterchainQueryKeeper.AllQueries(ctx) { @@ -1308,25 +1227,25 @@ func TestDelegationsCallbackAllPresentOneChange(t *testing.T) { } } - s.Require().Equal(1, delegationRequests) - s.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) + suite.Require().Equal(1, delegationRequests) + suite.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) } func TestDelegationsCallbackOneMissing(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() cdc := quicksilver.IBCKeeper.Codec() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -1345,9 +1264,9 @@ func TestDelegationsCallbackOneMissing(t *testing.T) { delegationQuery := stakingtypes.QueryDelegatorDelegationsRequest{DelegatorAddr: zone.DelegationAddress.Address, Pagination: &query.PageRequest{Limit: uint64(len(zone.Validators))}} bz := cdc.MustMarshal(&delegationQuery) - err := keeper.DelegationsCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID, Request: bz}) + err := keeper.DelegationsCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: bz}) - s.Require().NoError(err) + suite.Require().NoError(err) delegationRequests := 0 for _, query := range quicksilver.InterchainQueryKeeper.AllQueries(ctx) { @@ -1356,25 +1275,25 @@ func TestDelegationsCallbackOneMissing(t *testing.T) { } } - s.Require().Equal(1, delegationRequests) // callback for 'missing' delegation. - s.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) // new delegation doesn't get removed until the callback. + suite.Require().Equal(1, delegationRequests) // callback for 'missing' delegation. + suite.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) // new delegation doesn't get removed until the callback. } func TestDelegationsCallbackOneAdditional(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() cdc := quicksilver.IBCKeeper.Codec() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -1395,9 +1314,9 @@ func TestDelegationsCallbackOneAdditional(t *testing.T) { delegationQuery := stakingtypes.QueryDelegatorDelegationsRequest{DelegatorAddr: zone.DelegationAddress.Address, Pagination: &query.PageRequest{Limit: uint64(len(zone.Validators))}} bz := cdc.MustMarshal(&delegationQuery) - err := keeper.DelegationsCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID, Request: bz}) + err := keeper.DelegationsCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: bz}) - s.Require().NoError(err) + suite.Require().NoError(err) delegationRequests := 0 for _, query := range quicksilver.InterchainQueryKeeper.AllQueries(ctx) { @@ -1406,25 +1325,25 @@ func TestDelegationsCallbackOneAdditional(t *testing.T) { } } - s.Require().Equal(1, delegationRequests) - s.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) // new delegation doesn't get added until the end + suite.Require().Equal(1, delegationRequests) + suite.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) // new delegation doesn't get added until the end } func TestDelegationCallbackNew(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() cdc := quicksilver.IBCKeeper.Codec() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -1438,32 +1357,32 @@ func TestDelegationCallbackNew(t *testing.T) { data := cdc.MustMarshal(&response) delAddr, err := utils.AccAddressFromBech32(zone.DelegationAddress.Address, "") - s.Require().NoError(err) + suite.Require().NoError(err) valAddr, err := utils.ValAddressFromBech32(vals[3].OperatorAddress, "") - s.Require().NoError(err) + suite.Require().NoError(err) bz := stakingtypes.GetDelegationKey(delAddr, valAddr) - err = keeper.DelegationCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID, Request: bz}) - s.Require().NoError(err) + err = keeper.DelegationCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: bz}) + suite.Require().NoError(err) - s.Require().Equal(4, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) + suite.Require().Equal(4, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) } func TestDelegationCallbackUpdate(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() cdc := quicksilver.IBCKeeper.Codec() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -1477,32 +1396,32 @@ func TestDelegationCallbackUpdate(t *testing.T) { data := cdc.MustMarshal(&response) delAddr, err := utils.AccAddressFromBech32(zone.DelegationAddress.Address, "") - s.Require().NoError(err) + suite.Require().NoError(err) valAddr, err := utils.ValAddressFromBech32(vals[3].OperatorAddress, "") - s.Require().NoError(err) + suite.Require().NoError(err) bz := stakingtypes.GetDelegationKey(delAddr, valAddr) - err = keeper.DelegationCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID, Request: bz}) - s.Require().NoError(err) + err = keeper.DelegationCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: bz}) + suite.Require().NoError(err) - s.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) + suite.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) } func TestDelegationCallbackNoOp(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() cdc := quicksilver.IBCKeeper.Codec() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -1516,32 +1435,32 @@ func TestDelegationCallbackNoOp(t *testing.T) { data := cdc.MustMarshal(&response) delAddr, err := utils.AccAddressFromBech32(zone.DelegationAddress.Address, "") - s.Require().NoError(err) + suite.Require().NoError(err) valAddr, err := utils.ValAddressFromBech32(vals[3].OperatorAddress, "") - s.Require().NoError(err) + suite.Require().NoError(err) bz := stakingtypes.GetDelegationKey(delAddr, valAddr) - ctx = s.chainA.GetContext() - err = keeper.DelegationCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID, Request: bz}) - s.Require().NoError(err) + ctx = suite.chainA.GetContext() + err = keeper.DelegationCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: bz}) + suite.Require().NoError(err) - s.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) + suite.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) } func TestDelegationCallbackRemove(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() cdc := quicksilver.IBCKeeper.Codec() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -1555,13 +1474,13 @@ func TestDelegationCallbackRemove(t *testing.T) { data := cdc.MustMarshal(&response) delAddr, err := utils.AccAddressFromBech32(zone.DelegationAddress.Address, "") - s.Require().NoError(err) + suite.Require().NoError(err) valAddr, err := utils.ValAddressFromBech32(vals[3].OperatorAddress, "") - s.Require().NoError(err) + suite.Require().NoError(err) bz := stakingtypes.GetDelegationKey(delAddr, valAddr) - err = keeper.DelegationCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID, Request: bz}) - s.Require().NoError(err) + err = keeper.DelegationCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: bz}) + suite.Require().NoError(err) delegationRequests := 0 for _, query := range quicksilver.InterchainQueryKeeper.AllQueries(ctx) { @@ -1570,26 +1489,26 @@ func TestDelegationCallbackRemove(t *testing.T) { } } - s.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) + suite.Require().Equal(3, len(quicksilver.InterchainstakingKeeper.GetAllDelegations(ctx, &zone))) } func TestDepositIntervalCallback(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() data, err := base64.StdEncoding.DecodeString(depositTxFixture) res := tx.GetTxsEventResponse{} quicksilver.InterchainQueryKeeper.IBCKeeper.Codec().MustUnmarshal(data, &res) - s.Require().NoError(err) + suite.Require().NoError(err) - err = keeper.DepositIntervalCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID}) - s.Require().NoError(err) + err = keeper.DepositIntervalCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID}) + suite.Require().NoError(err) txQueryCount := 0 for _, query := range quicksilver.InterchainQueryKeeper.AllQueries(ctx) { if query.QueryType == "tendermint.Tx" { @@ -1597,44 +1516,44 @@ func TestDepositIntervalCallback(t *testing.T) { } } // check we have the correct number (29) tendermint.Tx ICQ requests from the above payload. - s.Require().Equal(int(res.Pagination.Total), txQueryCount) + suite.Require().Equal(int(res.Pagination.Total), txQueryCount) } func TestDepositIntervalCallbackWithExistingTxs(t *testing.T) { - s := new(KeeperTestSuite) - s.SetT(t) - s.SetupTest() - s.setupTestZones() + suite := new(KeeperTestSuite) + suite.SetT(t) + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() data, err := base64.StdEncoding.DecodeString(depositTxFixture) res := tx.GetTxsEventResponse{} quicksilver.InterchainQueryKeeper.IBCKeeper.Codec().MustUnmarshal(data, &res) - s.Require().NoError(err) + suite.Require().NoError(err) var msg banktypes.MsgSend _ = quicksilver.InterchainQueryKeeper.IBCKeeper.Codec().UnpackAny(res.TxResponses[0].Tx, msg) msgA := msg txrA := res.TxResponses[0] - quicksilver.InterchainstakingKeeper.SetReceipt(ctx, icstypes.Receipt{ChainId: s.chainB.ChainID, Sender: msgA.FromAddress, Txhash: txrA.TxHash, Amount: msgA.Amount}) + quicksilver.InterchainstakingKeeper.SetReceipt(ctx, icstypes.Receipt{ChainId: suite.chainB.ChainID, Sender: msgA.FromAddress, Txhash: txrA.TxHash, Amount: msgA.Amount}) _ = quicksilver.InterchainQueryKeeper.IBCKeeper.Codec().UnpackAny(res.TxResponses[1].Tx, msg) msgB := msg txrB := res.TxResponses[1] - quicksilver.InterchainstakingKeeper.SetReceipt(ctx, icstypes.Receipt{ChainId: s.chainB.ChainID, Sender: msgB.FromAddress, Txhash: txrB.TxHash, Amount: msgB.Amount}) + quicksilver.InterchainstakingKeeper.SetReceipt(ctx, icstypes.Receipt{ChainId: suite.chainB.ChainID, Sender: msgB.FromAddress, Txhash: txrB.TxHash, Amount: msgB.Amount}) _ = quicksilver.InterchainQueryKeeper.IBCKeeper.Codec().UnpackAny(res.TxResponses[2].Tx, msg) msgC := msg txrC := res.TxResponses[2] - quicksilver.InterchainstakingKeeper.SetReceipt(ctx, icstypes.Receipt{ChainId: s.chainB.ChainID, Sender: msgC.FromAddress, Txhash: txrC.TxHash, Amount: msgC.Amount}) + quicksilver.InterchainstakingKeeper.SetReceipt(ctx, icstypes.Receipt{ChainId: suite.chainB.ChainID, Sender: msgC.FromAddress, Txhash: txrC.TxHash, Amount: msgC.Amount}) - err = keeper.DepositIntervalCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: s.chainB.ChainID}) - s.Require().NoError(err) + err = keeper.DepositIntervalCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID}) + suite.Require().NoError(err) txQueryCount := 0 for _, query := range quicksilver.InterchainQueryKeeper.AllQueries(ctx) { if query.QueryType == "tendermint.Tx" { @@ -1642,37 +1561,37 @@ func TestDepositIntervalCallbackWithExistingTxs(t *testing.T) { } } // check we have the correct number (29 minus - 3 receipts = 26) tendermint.Tx ICQ requests from the above payload. - s.Require().Equal(int(res.Pagination.Total)-3, txQueryCount) + suite.Require().Equal(int(res.Pagination.Total)-3, txQueryCount) } -func (s *KeeperTestSuite) TestDelegationAccountBalanceCallback() { - s.Run("account balance", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallback() { + suite.Run("account balance", func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) quicksilver.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.DepositAddress.IncrementBalanceWaitgroup() zone.WithdrawalAddress.IncrementBalanceWaitgroup() quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) response := sdk.NewCoin("qck", sdk.NewInt(10)) respbz, err := quicksilver.AppCodec().Marshal(&response) - s.Require().NoError(err) + suite.Require().NoError(err) delAddr := zone.DelegationAddress.Address accAddr, err := utils.AccAddressFromBech32(delAddr, "cosmos") - s.Require().NoError(err) + suite.Require().NoError(err) data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("qck")...) - err = keeper.DelegationAccountBalanceCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: s.chainB.ChainID, Request: data}) + err = keeper.DelegationAccountBalanceCallback(&quicksilver.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data}) - s.Require().NoError(err) + suite.Require().NoError(err) }) } diff --git a/x/interchainstaking/keeper/delegation_test.go b/x/interchainstaking/keeper/delegation_test.go index e28d7d7df..0c860af24 100644 --- a/x/interchainstaking/keeper/delegation_test.go +++ b/x/interchainstaking/keeper/delegation_test.go @@ -12,41 +12,41 @@ import ( "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -func (s *KeeperTestSuite) TestKeeper_DelegationStore() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestKeeper_DelegationStore() { + suite.SetupTest() + suite.setupTestZones() - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() // get test zone - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - zoneValidatorAddresses := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + zoneValidatorAddresses := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId) performanceDelegations := icsKeeper.GetAllPerformanceDelegations(ctx, &zone) - s.Require().Len(performanceDelegations, 4) + suite.Require().Len(performanceDelegations, 4) performanceDelegationPointers := icsKeeper.GetAllPerformanceDelegationsAsPointer(ctx, &zone) for i, pdp := range performanceDelegationPointers { - s.Require().Equal(performanceDelegations[i], *pdp) + suite.Require().Equal(performanceDelegations[i], *pdp) } // update performance delegation updateDelegation, found := icsKeeper.GetPerformanceDelegation(ctx, &zone, zoneValidatorAddresses[0]) - s.Require().True(found) - s.Require().Equal(uint64(0), updateDelegation.Amount.Amount.Uint64()) + suite.Require().True(found) + suite.Require().Equal(uint64(0), updateDelegation.Amount.Amount.Uint64()) updateDelegation.Amount.Amount = sdkmath.NewInt(10000) icsKeeper.SetPerformanceDelegation(ctx, &zone, updateDelegation) updatedDelegation, found := icsKeeper.GetPerformanceDelegation(ctx, &zone, zoneValidatorAddresses[0]) - s.Require().True(found) - s.Require().Equal(updateDelegation, updatedDelegation) + suite.Require().True(found) + suite.Require().Equal(updateDelegation, updatedDelegation) // check that there are no delegations delegations := icsKeeper.GetAllDelegations(ctx, &zone) - s.Require().Len(delegations, 0) + suite.Require().Len(delegations, 0) // set delegations icsKeeper.SetDelegation( @@ -79,20 +79,20 @@ func (s *KeeperTestSuite) TestKeeper_DelegationStore() { // check for delegations set above delegations = icsKeeper.GetAllDelegations(ctx, &zone) - s.Require().Len(delegations, 3) + suite.Require().Len(delegations, 3) // load and match pointers delegationPointers := icsKeeper.GetAllDelegationsAsPointer(ctx, &zone) for i, dp := range delegationPointers { - s.Require().Equal(delegations[i], *dp) + suite.Require().Equal(delegations[i], *dp) } // get delegations for delegation address and match addr, err := sdk.AccAddressFromBech32(zone.DelegationAddress.GetAddress()) - s.Require().NoError(err) + suite.Require().NoError(err) dds := icsKeeper.GetDelegatorDelegations(ctx, &zone, addr) - s.Require().Len(dds, 3) - s.Require().Equal(delegations, dds) + suite.Require().Len(dds, 3) + suite.Require().Equal(delegations, dds) } type delegationUpdate struct { @@ -100,7 +100,7 @@ type delegationUpdate struct { absolute bool } -func (s *KeeperTestSuite) TestUpdateDelegation() { +func (suite *KeeperTestSuite) TestUpdateDelegation() { del1 := utils.GenerateAccAddressForTest() val1 := utils.GenerateValAddressForTest() @@ -195,14 +195,14 @@ func (s *KeeperTestSuite) TestUpdateDelegation() { for _, tt := range tests { tt := tt - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - qApp := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() - zone, found := qApp.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + qApp := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() + zone, found := qApp.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) if tt.delegation != nil { qApp.InterchainstakingKeeper.SetDelegation(ctx, &zone, *tt.delegation) @@ -210,439 +210,52 @@ func (s *KeeperTestSuite) TestUpdateDelegation() { for _, update := range tt.updates { err := qApp.InterchainstakingKeeper.UpdateDelegationRecordForAddress(ctx, update.delegation.DelegationAddress, update.delegation.ValidatorAddress, update.delegation.Amount, &zone, update.absolute) - s.Require().NoError(err) + suite.Require().NoError(err) } actual, found := qApp.InterchainstakingKeeper.GetDelegation(ctx, &zone, tt.expected.DelegationAddress, tt.expected.ValidatorAddress) - s.Require().True(found) - s.Require().Equal(tt.expected, actual) + suite.Require().True(found) + suite.Require().Equal(tt.expected, actual) }) } } -// func (s *KeeperTestSuite) TestCalculateDeltas() { - -// // we auto generate the validator addresses in these tests. any dust gets allocated to the first validator in the list -// // once sorted alphabetically on valoper. - -// val1 := utils.GenerateValAddressForTest() -// val2 := utils.GenerateValAddressForTest() -// val3 := utils.GenerateValAddressForTest() -// val4 := utils.GenerateValAddressForTest() - -// zone := types.Zone{Validators: []*types.Validator{ -// {ValoperAddress: val1.String(), CommissionRate: sdk.NewDecWithPrec(30, 2), Status: stakingtypes.BondStatusBonded}, -// {ValoperAddress: val2.String(), CommissionRate: sdk.NewDecWithPrec(25, 2), Status: stakingtypes.BondStatusBonded}, -// {ValoperAddress: val3.String(), CommissionRate: sdk.NewDecWithPrec(10, 2), Status: stakingtypes.BondStatusBonded}, -// {ValoperAddress: val4.String(), CommissionRate: sdk.NewDecWithPrec(12, 2), Status: stakingtypes.BondStatusBonded}, -// }} - -// zone2 := types.Zone{Validators: []*types.Validator{ -// {ValoperAddress: val1.String(), CommissionRate: sdk.NewDecWithPrec(30, 2), Status: stakingtypes.BondStatusBonded}, -// {ValoperAddress: val2.String(), CommissionRate: sdk.NewDecWithPrec(25, 2), Status: stakingtypes.BondStatusBonded}, -// {ValoperAddress: val3.String(), CommissionRate: sdk.NewDecWithPrec(10, 2), Status: stakingtypes.BondStatusBonded}, -// {ValoperAddress: val4.String(), CommissionRate: sdk.NewDecWithPrec(75, 2), Status: stakingtypes.BondStatusBonded}, -// }} - -// tc := []struct { -// current map[string]sdkmath.Int -// target func(qs *app.Quicksilver) types.ValidatorIntents {} -// expected types.ValidatorIntents -// }{ -// { -// current: map[string]sdkmath.Int{ -// val1.String(): sdk.NewInt(350000), -// val2.String(): sdk.NewInt(650000), -// val3.String(): sdk.NewInt(75000), -// }, -// target: func(qs *app.Quicksilver) types.ValidatorIntents { -// return types.ValidatorIntents{ -// {ValoperAddress: val1.String(), Weight: sdk.NewDecWithPrec(30, 2)}, -// {ValoperAddress: val2.String(), Weight: sdk.NewDecWithPrec(63, 2)}, -// {ValoperAddress: val3.String(), Weight: sdk.NewDecWithPrec(7, 2)}, -// } -// }, -// expected: types.ValidatorIntents{ -// {ValoperAddress: val2.String(), Weight: sdk.NewDec(27250)}, -// {ValoperAddress: val3.String(), Weight: sdk.NewDec(250)}, -// {ValoperAddress: val1.String(), Weight: sdk.NewDec(-27500)}, -// }, -// }, -// { -// current: map[string]sdkmath.Int{ -// val1.String(): sdk.NewInt(53), -// val2.String(): sdk.NewInt(26), -// val3.String(): sdk.NewInt(14), -// val4.String(): sdk.NewInt(7), -// }, -// target: func(qs *app.Quicksilver) types.ValidatorIntents { -// return types.ValidatorIntents{ -// {ValoperAddress: val1.String(), Weight: sdk.NewDecWithPrec(50, 2)}, -// {ValoperAddress: val2.String(), Weight: sdk.NewDecWithPrec(28, 2)}, -// {ValoperAddress: val3.String(), Weight: sdk.NewDecWithPrec(12, 2)}, -// {ValoperAddress: val4.String(), Weight: sdk.NewDecWithPrec(10, 2)}, -// } -// }, -// expected: types.ValidatorIntents{ -// {ValoperAddress: val4.String(), Weight: sdk.NewDec(3)}, -// {ValoperAddress: val2.String(), Weight: sdk.NewDec(2)}, -// {ValoperAddress: val3.String(), Weight: sdk.NewDec(-2)}, -// {ValoperAddress: val1.String(), Weight: sdk.NewDec(-3)}, -// }, -// }, -// { -// current: map[string]sdkmath.Int{ -// val1.String(): sdk.NewInt(30), -// val2.String(): sdk.NewInt(30), -// val3.String(): sdk.NewInt(60), -// val4.String(): sdk.NewInt(180), -// }, -// target: func(qs *app.Quicksilver) types.ValidatorIntents { -// return types.ValidatorIntents{ -// {ValoperAddress: val1.String(), Weight: sdk.NewDecWithPrec(50, 2)}, -// {ValoperAddress: val2.String(), Weight: sdk.NewDecWithPrec(25, 2)}, -// {ValoperAddress: val3.String(), Weight: sdk.NewDecWithPrec(15, 2)}, -// {ValoperAddress: val4.String(), Weight: sdk.NewDecWithPrec(10, 2)}, -// } -// }, -// expected: types.ValidatorIntents{ -// {ValoperAddress: val1.String(), Weight: sdk.NewDec(120)}, -// {ValoperAddress: val2.String(), Weight: sdk.NewDec(45)}, -// {ValoperAddress: val3.String(), Weight: sdk.NewDec(-15)}, -// {ValoperAddress: val4.String(), Weight: sdk.NewDec(-150)}, -// }, -// }, -// // default intent -- all equal -// { -// current: map[string]sdkmath.Int{ -// val1.String(): sdk.NewInt(15), -// val2.String(): sdk.NewInt(5), -// val3.String(): sdk.NewInt(20), -// val4.String(): sdk.NewInt(60), -// }, -// target: func(qs *app.Quicksilver) types.ValidatorIntents { -// return qs.InterchainstakingKeeper.GetAggregateIntentOrDefault(ctx, zone) -// }, -// expected: types.ValidatorIntents{ -// {ValoperAddress: val2.String(), Weight: sdk.NewDec(20)}, -// {ValoperAddress: val1.String(), Weight: sdk.NewDec(10)}, -// {ValoperAddress: val3.String(), Weight: sdk.NewDec(5)}, -// {ValoperAddress: val4.String(), Weight: sdk.NewDec(-35)}, -// }, -// }, -// { -// // GetAggregateIntentOrDefault will preclude val4 on account on high commission. -// current: map[string]sdkmath.Int{ -// val1.String(): sdk.NewInt(8), -// val2.String(): sdk.NewInt(12), -// val3.String(): sdk.NewInt(20), -// val4.String(): sdk.NewInt(60), -// }, -// target: func(qs *app.Quicksilver) types.ValidatorIntents { -// return qs.InterchainstakingKeeper.GetAggregateIntentOrDefault(ctx, zone2) -// }, -// expected: types.ValidatorIntents{ -// {ValoperAddress: val1.String(), Weight: sdk.NewDec(25)}, -// {ValoperAddress: val2.String(), Weight: sdk.NewDec(21)}, -// {ValoperAddress: val3.String(), Weight: sdk.NewDec(13)}, -// {ValoperAddress: val4.String(), Weight: sdk.NewDec(-60)}, -// }, -// }, -// } - -// for caseNumber, val := range tc { -// s.Run(fmt.Sprint("case %d", caseNumber), func() { -// s.SetupTest() -// s.setupTestZones() - -// app := s.GetQuicksilverApp(s.chainA) -// ctx := s.chainA.GetContext() - -// sum := sdkmath.ZeroInt() -// for _, amount := range val.current { -// sum = sum.Add(amount) -// } -// deltas := types.CalculateDeltas(val.current, sum, val.(app)) -// s.Require().Equal(len(val.expected), len(deltas), fmt.Sprintf("expected %d RebalanceTargets in case %d, got %d", len(val.expected), caseNumber, len(deltas))) -// for idx, expected := range val.expected { -// s.Require().Equal(expected, deltas[idx], fmt.Sprintf("case %d, idx %d: Expected %v, got %v", caseNumber, idx, expected, deltas[idx])) -// } -// }) -// } -// } - -/*func TestDetermineAllocationsForRebalance(t *testing.T) { - // we auto generate the validator addresses in these tests. any dust gets allocated to the first validator in the list - // once sorted alphabetically on valoper. +func (suite *KeeperTestSuite) TestStoreGetDeleteDelegation() { + suite.Run("delegation - store / get / delete", func() { + suite.SetupTest() + suite.setupTestZones() - val1 := utils.GenerateValAddressForTest() - val2 := utils.GenerateValAddressForTest() - val3 := utils.GenerateValAddressForTest() - val4 := utils.GenerateValAddressForTest() - - zone := types.Zone{Validators: []*types.Validator{ - {ValoperAddress: val1.String(), CommissionRate: sdk.NewDecWithPrec(30, 2), Status: stakingtypes.BondStatusBonded}, - {ValoperAddress: val2.String(), CommissionRate: sdk.NewDecWithPrec(25, 2), Status: stakingtypes.BondStatusBonded}, - {ValoperAddress: val3.String(), CommissionRate: sdk.NewDecWithPrec(10, 2), Status: stakingtypes.BondStatusBonded}, - {ValoperAddress: val4.String(), CommissionRate: sdk.NewDecWithPrec(12, 2), Status: stakingtypes.BondStatusBonded}, - }} - - zone2 := types.Zone{Validators: []*types.Validator{ - {ValoperAddress: val1.String(), CommissionRate: sdk.NewDecWithPrec(30, 2), Status: stakingtypes.BondStatusBonded}, - {ValoperAddress: val2.String(), CommissionRate: sdk.NewDecWithPrec(25, 2), Status: stakingtypes.BondStatusBonded}, - {ValoperAddress: val3.String(), CommissionRate: sdk.NewDecWithPrec(10, 2), Status: stakingtypes.BondStatusBonded}, - {ValoperAddress: val4.String(), CommissionRate: sdk.NewDecWithPrec(75, 2), Status: stakingtypes.BondStatusBonded}, - }} - - tc := []struct { - name string - current map[string]sdkmath.Int - locked map[string]bool - target types.ValidatorIntents - expected []types.RebalanceTarget - dust sdkmath.Int - redelegations []types.RedelegationRecord - }{ - { - name: "case 1", - current: map[string]sdkmath.Int{ - val1.String(): sdk.NewInt(350000), - val2.String(): sdk.NewInt(650000), - val3.String(): sdk.NewInt(75000), - }, - target: types.ValidatorIntents{ - {ValoperAddress: val1.String(), Weight: sdk.NewDecWithPrec(30, 2)}, - {ValoperAddress: val2.String(), Weight: sdk.NewDecWithPrec(63, 2)}, - {ValoperAddress: val3.String(), Weight: sdk.NewDecWithPrec(7, 2)}, - }, - expected: []types.RebalanceTarget{ - {Amount: sdkmath.NewInt(27250), Source: val1.String(), Target: val2.String()}, - {Amount: sdkmath.NewInt(250), Source: val1.String(), Target: val3.String()}, - }, - }, - { - name: "case 2", - current: map[string]sdkmath.Int{ - val1.String(): sdk.NewInt(56), - val2.String(): sdk.NewInt(24), - val3.String(): sdk.NewInt(14), - val4.String(): sdk.NewInt(5), - }, - target: types.ValidatorIntents{ - {ValoperAddress: val1.String(), Weight: sdk.NewDecWithPrec(50, 2)}, - {ValoperAddress: val2.String(), Weight: sdk.NewDecWithPrec(28, 2)}, - {ValoperAddress: val3.String(), Weight: sdk.NewDecWithPrec(12, 2)}, - {ValoperAddress: val4.String(), Weight: sdk.NewDecWithPrec(10, 2)}, - }, - expected: []types.RebalanceTarget{ - {Amount: sdkmath.NewInt(4), Source: val1.String(), Target: val4.String()}, - {Amount: sdkmath.NewInt(3), Source: val1.String(), Target: val2.String()}, - }, - redelegations: []types.RedelegationRecord{}, - }, - { - name: "case 3", - current: map[string]sdkmath.Int{ - val1.String(): sdk.NewInt(30), - val2.String(): sdk.NewInt(30), - val3.String(): sdk.NewInt(60), - val4.String(): sdk.NewInt(180), - }, - target: types.ValidatorIntents{ - {ValoperAddress: val1.String(), Weight: sdk.NewDecWithPrec(50, 2)}, - {ValoperAddress: val2.String(), Weight: sdk.NewDecWithPrec(25, 2)}, - {ValoperAddress: val3.String(), Weight: sdk.NewDecWithPrec(15, 2)}, - {ValoperAddress: val4.String(), Weight: sdk.NewDecWithPrec(10, 2)}, - }, - expected: []types.RebalanceTarget{ - {Amount: sdkmath.NewInt(42), Source: val4.String(), Target: val1.String()}, - // below values _would_ applied, if we weren't limited by a max of total/7 - // {Amount: sdkmath.NewInt(10), Source: val4.String(), Target: val2.String()}, - }, - redelegations: []types.RedelegationRecord{}, - }, - // default intent -- all equal - { - name: "case 4 - default intent, all equal", - current: map[string]sdkmath.Int{ - val1.String(): sdk.NewInt(15), - val2.String(): sdk.NewInt(5), - val3.String(): sdk.NewInt(20), - val4.String(): sdk.NewInt(60), - }, - target: zone.GetAggregateIntentOrDefault(), - expected: []types.RebalanceTarget{ - {Amount: sdkmath.NewInt(14), Source: val4.String(), Target: val2.String()}, - // below values _would_ applied, if we weren't limited by a max of total/7 - // {Amount: sdkmath.NewInt(10), Source: val4.String(), Target: val1.String()}, - // {Amount: sdkmath.NewInt(5), Source: val4.String(), Target: val3.String()}, - }, - redelegations: []types.RedelegationRecord{}, - }, - // - { - name: "case 5 - default intent with val4 high commission; truncate rebalance to 50% of tvl", - current: map[string]sdkmath.Int{ - val1.String(): sdk.NewInt(8), - val2.String(): sdk.NewInt(12), - val3.String(): sdk.NewInt(20), - val4.String(): sdk.NewInt(60), - }, - target: zone2.GetAggregateIntentOrDefault(), - expected: []types.RebalanceTarget{ - {Amount: sdkmath.NewInt(14), Source: val4.String(), Target: val1.String()}, - // below values _would_ applied, if we weren't limited by a max of total/7 - // {Amount: sdkmath.NewInt(21), Source: val4.String(), Target: val2.String()}, - // {Amount: sdkmath.NewInt(4), Source: val4.String(), Target: val3.String()}, - }, - redelegations: []types.RedelegationRecord{}, - }, - { - name: "case 6 - includes redelegation, no impact", - current: map[string]sdkmath.Int{ - val1.String(): sdk.NewInt(8), - val2.String(): sdk.NewInt(12), - val3.String(): sdk.NewInt(20), - val4.String(): sdk.NewInt(60), - }, - target: zone2.GetAggregateIntentOrDefault(), - expected: []types.RebalanceTarget{ - {Amount: sdkmath.NewInt(14), Source: val4.String(), Target: val1.String()}, - // below values _would_ applied, if we weren't limited by a max of total/7 - // {Amount: sdkmath.NewInt(21), Source: val4.String(), Target: val2.String()}, - // {Amount: sdkmath.NewInt(4), Source: val4.String(), Target: val3.String()}, - }, - redelegations: []types.RedelegationRecord{ - {ChainId: "test-1", EpochNumber: 1, Source: val2.String(), Destination: val4.String(), Amount: 30, CompletionTime: time.Now().Add(time.Hour)}, - }, - }, - { - name: "case 7 - includes redelegation, truncated delegation", - current: map[string]sdkmath.Int{ - val1.String(): sdk.NewInt(8), - val2.String(): sdk.NewInt(12), - val3.String(): sdk.NewInt(20), - val4.String(): sdk.NewInt(60), - }, - target: zone2.GetAggregateIntentOrDefault(), - expected: []types.RebalanceTarget{ - {Amount: sdkmath.NewInt(10), Source: val4.String(), Target: val1.String()}, - // below values _would_ applied, if we weren't limited by a max of total/7 - // {Amount: sdkmath.NewInt(21), Source: val4.String(), Target: val2.String()}, - // {Amount: sdkmath.NewInt(4), Source: val4.String(), Target: val3.String()}, - }, - redelegations: []types.RedelegationRecord{ - {ChainId: "test-1", EpochNumber: 1, Source: val2.String(), Destination: val4.String(), Amount: 50, CompletionTime: time.Now().Add(time.Hour)}, - }, - }, - { - name: "case 8 - includes redelegation, truncated delegation", - current: map[string]sdkmath.Int{ - val1.String(): sdk.NewInt(8), - val2.String(): sdk.NewInt(12), - val3.String(): sdk.NewInt(20), - val4.String(): sdk.NewInt(60), - }, - target: zone2.GetAggregateIntentOrDefault(), - expected: []types.RebalanceTarget{ - {Amount: sdkmath.NewInt(10), Source: val4.String(), Target: val1.String()}, - // below values _would_ applied, if we weren't limited by a max of total/7 - // {Amount: sdkmath.NewInt(21), Source: val4.String(), Target: val2.String()}, - // {Amount: sdkmath.NewInt(4), Source: val4.String(), Target: val3.String()}, - }, - redelegations: []types.RedelegationRecord{ - {ChainId: "test-1", EpochNumber: 1, Source: val2.String(), Destination: val4.String(), Amount: 50, CompletionTime: time.Now().Add(time.Hour)}, - }, - }, - { - name: "case 9 - includes redelegation, truncated delegation overflow", - current: map[string]sdkmath.Int{ - val1.String(): sdk.NewInt(2), - val2.String(): sdk.NewInt(8), - val3.String(): sdk.NewInt(30), - val4.String(): sdk.NewInt(60), - }, - target: zone2.GetAggregateIntentOrDefault(), - expected: []types.RebalanceTarget{ - {Amount: sdkmath.NewInt(10), Source: val4.String(), Target: val1.String()}, - // below values _would_ applied, if we weren't limited by a max of total/7 - // {Amount: sdkmath.NewInt(4), Source: val3.String(), Target: val1.String()}, // joe: I would expect this to be included... - // {Amount: sdkmath.NewInt(4), Source: val4.String(), Target: val3.String()}, - }, - redelegations: []types.RedelegationRecord{ - {ChainId: "test-1", EpochNumber: 1, Source: val2.String(), Destination: val4.String(), Amount: 50, CompletionTime: time.Now().Add(time.Hour)}, - }, - }, - { - name: "case 10 - includes redelegation, zero delegation", - current: map[string]sdkmath.Int{ - val1.String(): sdk.NewInt(8), - val2.String(): sdk.NewInt(12), - val3.String(): sdk.NewInt(20), - val4.String(): sdk.NewInt(60), - }, - target: zone2.GetAggregateIntentOrDefault(), - expected: []types.RebalanceTarget{ - // {Amount: sdkmath.NewInt(10), Source: val4.String(), Target: val1.String()}, - // below values _would_ applied, if we weren't limited by a max of total/7 - // {Amount: sdkmath.NewInt(21), Source: val4.String(), Target: val2.String()}, - // {Amount: sdkmath.NewInt(4), Source: val4.String(), Target: val3.String()}, - }, - redelegations: []types.RedelegationRecord{ - {ChainId: "test-1", EpochNumber: 1, Source: val2.String(), Destination: val4.String(), Amount: 60, CompletionTime: time.Now().Add(time.Hour)}, - }, - }, - } - - for _, val := range tc { - sum := sdkmath.ZeroInt() - for _, amount := range val.current { - sum = sum.Add(amount) - } - allocations := types.DetermineAllocationsForRebalancing(val.current, val.locked, sum, val.target, val.redelegations, nil) - require.Equal(t, len(val.expected), len(allocations), fmt.Sprintf("expected %d RebalanceTargets in '%s', got %d", len(val.expected), val.name, len(allocations))) - for idx, rebalance := range val.expected { - require.Equal(t, rebalance, allocations[idx], fmt.Sprintf("%s, idx %d: Expected %v, got %v", val.name, idx, rebalance, allocations[idx])) - } - } -}*/ - -func (s *KeeperTestSuite) TestStoreGetDeleteDelegation() { - s.Run("delegation - store / get / delete", func() { - s.SetupTest() - s.setupTestZones() - - qApp := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + qApp := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - zone, found := qApp.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := qApp.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) delegator := utils.GenerateAccAddressForTest() validator := utils.GenerateValAddressForTest() _, found = qApp.InterchainstakingKeeper.GetDelegation(ctx, &zone, delegator.String(), validator.String()) - s.Require().False(found) + suite.Require().False(found) newDelegation := types.NewDelegation(delegator.String(), validator.String(), sdk.NewCoin("uatom", sdk.NewInt(5000))) qApp.InterchainstakingKeeper.SetDelegation(ctx, &zone, newDelegation) fetchedDelegation, found := qApp.InterchainstakingKeeper.GetDelegation(ctx, &zone, delegator.String(), validator.String()) - s.Require().True(found) - s.Require().Equal(newDelegation, fetchedDelegation) + suite.Require().True(found) + suite.Require().Equal(newDelegation, fetchedDelegation) allDelegations := qApp.InterchainstakingKeeper.GetAllDelegations(ctx, &zone) - s.Require().Len(allDelegations, 1) + suite.Require().Len(allDelegations, 1) err := qApp.InterchainstakingKeeper.RemoveDelegation(ctx, &zone, newDelegation) - s.Require().NoError(err) + suite.Require().NoError(err) allDelegations2 := qApp.InterchainstakingKeeper.GetAllDelegations(ctx, &zone) - s.Require().Len(allDelegations2, 0) + suite.Require().Len(allDelegations2, 0) }) } -func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { +func (suite *KeeperTestSuite) TestFlushOutstandingDelegations() { userAddress := utils.GenerateAccAddressForTest().String() denom := "uatom" tests := []struct { @@ -669,7 +282,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { receiptTwoTime := cutOffTime.Add(-3 * time.Hour) rcpt1 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit01", Amount: sdk.NewCoins( @@ -683,7 +296,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { } rcpt2 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit02", Amount: sdk.NewCoins( @@ -701,8 +314,8 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { delAddrBalance: sdk.NewCoin("uatom", sdkmath.NewInt(0)), assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { count := 0 - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) quicksilver.InterchainstakingKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) { if receiptInfo.Completed == nil { count++ @@ -711,7 +324,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { return false }) - s.Require().Equal(0, count) + suite.Require().Equal(0, count) return true }, }, @@ -723,7 +336,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { receiptTwoTime := cutOffTime.Add(2 * time.Hour) rcpt1 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit01", Amount: sdk.NewCoins( @@ -737,7 +350,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { } rcpt2 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit02", Amount: sdk.NewCoins( @@ -754,15 +367,15 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { delAddrBalance: sdk.NewCoin("uatom", sdkmath.NewInt(100)), assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { count := 0 - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) quicksilver.InterchainstakingKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) { if receiptInfo.Completed == nil { count++ } return false }) - s.Require().Equal(1, count) + suite.Require().Equal(1, count) return true }, }, @@ -774,7 +387,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { receiptTwoTime := cutOffTime.Add(2 * time.Hour) // -22h rcpt1 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit01", Amount: sdk.NewCoins( @@ -788,7 +401,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { } rcpt2 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit02", Amount: sdk.NewCoins( @@ -806,15 +419,15 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { delAddrBalance: sdk.NewCoin("uatom", sdkmath.NewInt(2000100)), assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { count := 0 - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) quicksilver.InterchainstakingKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) { if receiptInfo.Completed == nil { count++ } return false }) - s.Require().Equal(1, count) + suite.Require().Equal(1, count) return true }, mockAck: true, @@ -828,7 +441,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { receiptTwoTime := cutOffTime.Add(-3 * time.Hour) rcpt1 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit01", Amount: sdk.NewCoins( @@ -842,7 +455,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { } rcpt2 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit02", Amount: sdk.NewCoins( @@ -860,15 +473,15 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { delAddrBalance: sdk.NewCoin("uatom", sdkmath.NewInt(2000100)), assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { count := 0 - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) quicksilver.InterchainstakingKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) { if receiptInfo.Completed == nil { count++ } return false }) - s.Require().Equal(0, count) + suite.Require().Equal(0, count) return true }, mockAck: true, @@ -882,7 +495,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { receiptTwoTime := cutOffTime.Add(2 * time.Hour) rcpt1 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit01", Amount: sdk.NewCoins( @@ -896,7 +509,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { } rcpt2 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit02", Amount: sdk.NewCoins( @@ -914,15 +527,15 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { delAddrBalance: sdk.NewCoin("uatom", sdkmath.NewInt(0)), assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { count := 0 - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) quicksilver.InterchainstakingKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) { if receiptInfo.Completed == nil { count++ } return false }) - s.Require().Equal(1, count) + suite.Require().Equal(1, count) return true }, // zero delegation balance must mean that we cannot delegate anything. @@ -934,7 +547,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { cutOffTime := ctx.BlockTime().AddDate(0, 0, -1) receiptOneTime := cutOffTime.Add(-2 * time.Hour) rcpt1 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit01", Amount: sdk.NewCoins( @@ -948,7 +561,7 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { } rcpt2 := types.Receipt{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Sender: userAddress, Txhash: "TestDeposit02", Amount: sdk.NewCoins( @@ -966,15 +579,15 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { delAddrBalance: sdk.NewCoin("uatom", sdkmath.NewInt(100)), assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { count := 0 - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) quicksilver.InterchainstakingKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) { if receiptInfo.Completed == nil { count++ } return false }) - s.Require().Equal(0, count) + suite.Require().Equal(0, count) return true }, // delegation balance == 100, which equals the value of the second receipt. @@ -984,35 +597,35 @@ func (s *KeeperTestSuite) TestFlushOutstandingDelegations() { } for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(test.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() test.setStatements(ctx, quicksilver) - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) // before := quicksilver.InterchainstakingKeeper.AllReceipts(ctx) err := quicksilver.InterchainstakingKeeper.FlushOutstandingDelegations(ctx, &zone, test.delAddrBalance) // refetch zone after FlushOutstandingDelegations setZone(). - ctx = s.chainA.GetContext() + ctx = suite.chainA.GetContext() if test.mockAck { var msgs []sdk.Msg allocations, err := quicksilver.InterchainstakingKeeper.DeterminePlanForDelegation(ctx, &zone, test.expectedDelegation) - s.Require().NoError(err) + suite.Require().NoError(err) msgs = append(msgs, quicksilver.InterchainstakingKeeper.PrepareDelegationMessagesForCoins(&zone, allocations)...) for _, msg := range msgs { err := quicksilver.InterchainstakingKeeper.HandleDelegate(ctx, msg, "batch/1577836910") - s.Require().NoError(err) + suite.Require().NoError(err) } } // after := quicksilver.InterchainstakingKeeper.AllReceipts(ctx) // fmt.Println(before, after) - s.Require().NoError(err) + suite.Require().NoError(err) isCorrect := test.assertStatements(ctx, quicksilver) - s.Require().True(isCorrect) + suite.Require().True(isCorrect) }) } } diff --git a/x/interchainstaking/keeper/fuzz_test.go b/x/interchainstaking/keeper/fuzz_test.go index 109f838bd..92cf06143 100644 --- a/x/interchainstaking/keeper/fuzz_test.go +++ b/x/interchainstaking/keeper/fuzz_test.go @@ -156,11 +156,11 @@ func FuzzValsetCallback(f *testing.F) { }) } -func (s *FuzzingTestSuite) FuzzValsetCallback(args []byte) { - app := s.GetQuicksilverApp(s.chainA) +func (suite *FuzzingTestSuite) FuzzValsetCallback(args []byte) { + app := suite.GetQuicksilverApp(suite.chainA) app.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - err := keeper.ValsetCallback(&app.InterchainstakingKeeper, ctx, args, icqtypes.Query{ChainId: s.chainB.ChainID}) - s.Require().NoError(err) + err := keeper.ValsetCallback(&app.InterchainstakingKeeper, ctx, args, icqtypes.Query{ChainId: suite.chainB.ChainID}) + suite.Require().NoError(err) } diff --git a/x/interchainstaking/keeper/grpc_query_test.go b/x/interchainstaking/keeper/grpc_query_test.go index a160c675f..c7a1a1e02 100644 --- a/x/interchainstaking/keeper/grpc_query_test.go +++ b/x/interchainstaking/keeper/grpc_query_test.go @@ -12,9 +12,9 @@ import ( "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -func (s *KeeperTestSuite) TestKeeper_Zones() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestKeeper_Zones() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -41,7 +41,7 @@ func (s *KeeperTestSuite) TestKeeper_Zones() { "Zones_Valid_Request", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() }, &types.QueryZonesRequest{}, false, @@ -51,32 +51,32 @@ func (s *KeeperTestSuite) TestKeeper_Zones() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.Zones( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.expectLength, len(resp.Zones)) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.expectLength, len(resp.Zones)) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } -func (s *KeeperTestSuite) TestKeeper_ZoneValidators() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestKeeper_ZoneValidators() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -103,7 +103,7 @@ func (s *KeeperTestSuite) TestKeeper_ZoneValidators() { "ZoneValidatorsInfo_Valid_Request", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() }, &types.QueryZoneValidatorsRequest{}, false, @@ -113,32 +113,32 @@ func (s *KeeperTestSuite) TestKeeper_ZoneValidators() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.ZoneValidators( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.expectLength, len(resp.Validators)) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.expectLength, len(resp.Validators)) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } -func (s *KeeperTestSuite) TestKeeper_DepositAccount() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestKeeper_DepositAccount() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -162,7 +162,7 @@ func (s *KeeperTestSuite) TestKeeper_DepositAccount() { "DepositAccount_Invalid_Request", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() }, &types.QueryDepositAccountForChainRequest{}, true, @@ -173,7 +173,7 @@ func (s *KeeperTestSuite) TestKeeper_DepositAccount() { // use state set from previous tests }, &types.QueryDepositAccountForChainRequest{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, }, false, }, @@ -181,31 +181,31 @@ func (s *KeeperTestSuite) TestKeeper_DepositAccount() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.DepositAccount( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) + suite.Require().NoError(err) + suite.Require().NotNil(resp) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } -func (s *KeeperTestSuite) TestKeeper_DelegatorIntent() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestKeeper_DelegatorIntent() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -225,7 +225,7 @@ func (s *KeeperTestSuite) TestKeeper_DelegatorIntent() { "DelegatorIntent_Invalid_Zone", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() }, &types.QueryDelegatorIntentRequest{ ChainId: "boguschain", @@ -238,7 +238,7 @@ func (s *KeeperTestSuite) TestKeeper_DelegatorIntent() { "DelegatorIntent_No_Zone_Intents", func() {}, &types.QueryDelegatorIntentRequest{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, DelegatorAddress: testAddress, }, false, @@ -248,7 +248,7 @@ func (s *KeeperTestSuite) TestKeeper_DelegatorIntent() { "DelegatorIntent_No_Delegator_Intents", func() {}, &types.QueryDelegatorIntentRequest{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, DelegatorAddress: testAddress, }, false, @@ -257,10 +257,10 @@ func (s *KeeperTestSuite) TestKeeper_DelegatorIntent() { { "DelegatorIntent_Valid_Intents", func() { - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) // give funds - s.giveFunds(ctx, zone.LocalDenom, 5000000, testAddress) + suite.giveFunds(ctx, zone.LocalDenom, 5000000, testAddress) // set intents // TODO: set standardized intents for keeper_test package intents := []types.DelegatorIntent{ @@ -268,7 +268,7 @@ func (s *KeeperTestSuite) TestKeeper_DelegatorIntent() { Delegator: testAddress, Intents: types.ValidatorIntents{ &types.ValidatorIntent{ - ValoperAddress: icsKeeper.GetValidators(ctx, s.chainB.ChainID)[0].ValoperAddress, + ValoperAddress: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress, Weight: sdk.OneDec(), }, }, @@ -279,7 +279,7 @@ func (s *KeeperTestSuite) TestKeeper_DelegatorIntent() { } }, &types.QueryDelegatorIntentRequest{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, DelegatorAddress: testAddress, }, false, @@ -289,32 +289,32 @@ func (s *KeeperTestSuite) TestKeeper_DelegatorIntent() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.DelegatorIntent( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.expectLength, len(resp.Intent.Intents)) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.expectLength, len(resp.Intent.Intents)) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } -func (s *KeeperTestSuite) TestKeeper_Delegations() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestKeeper_Delegations() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -334,7 +334,7 @@ func (s *KeeperTestSuite) TestKeeper_Delegations() { "Delegations_Invalid_Zone", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() }, &types.QueryDelegationsRequest{ ChainId: "boguschain", @@ -346,7 +346,7 @@ func (s *KeeperTestSuite) TestKeeper_Delegations() { "Delegations_No_Zone_Delegations", func() {}, &types.QueryDelegationsRequest{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, }, false, 0, @@ -354,20 +354,20 @@ func (s *KeeperTestSuite) TestKeeper_Delegations() { { "Delegations_Valid_Delegations", func() { - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) // set delegation // TODO: set standardized delegations for keeper_test package delegation := types.Delegation{ DelegationAddress: testAddress, - ValidatorAddress: icsKeeper.GetValidators(ctx, s.chainB.ChainID)[0].ValoperAddress, + ValidatorAddress: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress, Amount: sdk.NewCoin("denom", sdk.NewInt(15000)), } icsKeeper.SetDelegation(ctx, &zone, delegation) }, &types.QueryDelegationsRequest{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, }, false, 1, @@ -376,32 +376,32 @@ func (s *KeeperTestSuite) TestKeeper_Delegations() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.Delegations( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.expectLength, len(resp.Delegations)) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.expectLength, len(resp.Delegations)) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } -func (s *KeeperTestSuite) TestKeeper_Receipts() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestKeeper_Receipts() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -421,7 +421,7 @@ func (s *KeeperTestSuite) TestKeeper_Receipts() { "Receipts_Invalid_Zone", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() }, &types.QueryReceiptsRequest{ ChainId: "boguschain", @@ -433,7 +433,7 @@ func (s *KeeperTestSuite) TestKeeper_Receipts() { "Receipts_No_Zone_Receipts", func() {}, &types.QueryReceiptsRequest{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, }, false, 0, @@ -441,8 +441,8 @@ func (s *KeeperTestSuite) TestKeeper_Receipts() { { "Receipts_Valid_Receipts", func() { - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) // set receipts receipt := icsKeeper.NewReceipt( @@ -457,7 +457,7 @@ func (s *KeeperTestSuite) TestKeeper_Receipts() { icsKeeper.SetReceipt(ctx, *receipt) }, &types.QueryReceiptsRequest{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, }, false, 1, @@ -466,32 +466,32 @@ func (s *KeeperTestSuite) TestKeeper_Receipts() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.Receipts( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.expectLength, len(resp.Receipts)) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.expectLength, len(resp.Receipts)) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } -func (s *KeeperTestSuite) TestKeeper_ZoneWithdrawalRecords() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestKeeper_ZoneWithdrawalRecords() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -511,7 +511,7 @@ func (s *KeeperTestSuite) TestKeeper_ZoneWithdrawalRecords() { "ZoneWithdrawalRecords_Invalid_Zone", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() }, &types.QueryWithdrawalRecordsRequest{ ChainId: "boguschain", @@ -523,7 +523,7 @@ func (s *KeeperTestSuite) TestKeeper_ZoneWithdrawalRecords() { "ZoneWithdrawalRecords_No_Zone_Records", func() {}, &types.QueryWithdrawalRecordsRequest{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, DelegatorAddress: "quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure", }, false, @@ -532,16 +532,16 @@ func (s *KeeperTestSuite) TestKeeper_ZoneWithdrawalRecords() { { "ZoneWithdrawalRecords_Valid_Records", func() { - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) distribution := []*types.Distribution{ { - Valoper: icsKeeper.GetValidators(ctx, s.chainB.ChainID)[0].ValoperAddress, + Valoper: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress, Amount: 10000000, }, { - Valoper: icsKeeper.GetValidators(ctx, s.chainB.ChainID)[1].ValoperAddress, + Valoper: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[1].ValoperAddress, Amount: 20000000, }, } @@ -561,7 +561,7 @@ func (s *KeeperTestSuite) TestKeeper_ZoneWithdrawalRecords() { ) }, &types.QueryWithdrawalRecordsRequest{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, DelegatorAddress: "quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure", }, false, @@ -571,32 +571,32 @@ func (s *KeeperTestSuite) TestKeeper_ZoneWithdrawalRecords() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.ZoneWithdrawalRecords( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.expectLength, len(resp.Withdrawals)) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.expectLength, len(resp.Withdrawals)) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } -func (s *KeeperTestSuite) TestKeeper_WithdrawalRecords() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestKeeper_WithdrawalRecords() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -616,7 +616,7 @@ func (s *KeeperTestSuite) TestKeeper_WithdrawalRecords() { "WithdrawalRecords_No_Zone_Records", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() }, &types.QueryWithdrawalRecordsRequest{}, false, @@ -625,16 +625,16 @@ func (s *KeeperTestSuite) TestKeeper_WithdrawalRecords() { { "WithdrawalRecords_Valid_Records", func() { - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) distribution := []*types.Distribution{ { - Valoper: icsKeeper.GetValidators(ctx, s.chainB.ChainID)[0].ValoperAddress, + Valoper: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress, Amount: 10000000, }, { - Valoper: icsKeeper.GetValidators(ctx, s.chainB.ChainID)[1].ValoperAddress, + Valoper: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[1].ValoperAddress, Amount: 20000000, }, } @@ -661,32 +661,32 @@ func (s *KeeperTestSuite) TestKeeper_WithdrawalRecords() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.WithdrawalRecords( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.expectLength, len(resp.Withdrawals)) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.expectLength, len(resp.Withdrawals)) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } -func (s *KeeperTestSuite) TestKeeper_UnbondingRecords() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestKeeper_UnbondingRecords() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -706,7 +706,7 @@ func (s *KeeperTestSuite) TestKeeper_UnbondingRecords() { "UnbondingRecords_No_Zone_Records", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() }, &types.QueryUnbondingRecordsRequest{}, false, @@ -715,15 +715,15 @@ func (s *KeeperTestSuite) TestKeeper_UnbondingRecords() { { "UnbondingRecords_Valid_Records", func() { - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) icsKeeper.SetUnbondingRecord( ctx, types.UnbondingRecord{ ChainId: zone.ChainId, EpochNumber: 1, - Validator: icsKeeper.GetValidators(ctx, s.chainB.ChainID)[0].ValoperAddress, + Validator: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress, RelatedTxhash: []string{"ABC012"}, }, ) @@ -736,32 +736,32 @@ func (s *KeeperTestSuite) TestKeeper_UnbondingRecords() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.UnbondingRecords( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.expectLength, len(resp.Unbondings)) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.expectLength, len(resp.Unbondings)) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } -func (s *KeeperTestSuite) TestKeeper_RedelegationRecords() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestKeeper_RedelegationRecords() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -781,7 +781,7 @@ func (s *KeeperTestSuite) TestKeeper_RedelegationRecords() { "RedelegationRecords_No_Zone_Records", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() }, &types.QueryRedelegationRecordsRequest{}, false, @@ -790,16 +790,16 @@ func (s *KeeperTestSuite) TestKeeper_RedelegationRecords() { { "RedelegationRecords_Valid_Records", func() { - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) icsKeeper.SetRedelegationRecord( ctx, types.RedelegationRecord{ ChainId: zone.ChainId, EpochNumber: 1, - Source: icsKeeper.GetValidators(ctx, s.chainB.ChainID)[1].ValoperAddress, - Destination: icsKeeper.GetValidators(ctx, s.chainB.ChainID)[0].ValoperAddress, + Source: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[1].ValoperAddress, + Destination: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress, Amount: 10000000, }) }, @@ -811,25 +811,25 @@ func (s *KeeperTestSuite) TestKeeper_RedelegationRecords() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.RedelegationRecords( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.expectLength, len(resp.Redelegations)) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.expectLength, len(resp.Redelegations)) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index 1f2c6d630..66352c6c9 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -84,40 +84,6 @@ func TestHandleMsgTransferBadRecipient(t *testing.T) { require.Error(t, quicksilver.InterchainstakingKeeper.HandleMsgTransfer(ctx, &transferMsg)) } -// TODO: add test cases for send. -// func (s *KeeperTestSuite) TestHandleSendToDelegate() { -// tests := []struct { -// name string -// }{ -// { -// name: "valid", -// }, -// } - -// for _, test := range tests { -// s.Run(test.name, func() { - -// s.SetupTest() -// s.setupTestZones() - -// recipient := utils.GenerateAccAddressForTest() -// app := s.GetQuicksilverApp(s.chainA) -// ctx := s.chainA.GetContext() -// ctx = ctx.WithContext(context.WithValue(ctx.Context(), utils.ContextKey("connectionID"), s.path.EndpointA.ConnectionID)) - -// sender := utils.GenerateAccAddressForTest() -// senderAddr, _ := sdk.Bech32ifyAddressBytes("cosmos", sender) - -// sendMsg := banktypes.MsgSend{ -// FromAddress: senderAddr, -// ToAddress: recipient.String(), -// Amount: sdk.NewCoins(sdk.NewCoin("denom", sdk.NewInt(100))), -// } -// s.Require().NoError(app.InterchainstakingKeeper.HandleCompleteSend(ctx, &sendMsg, "")) -// }) -// } -// } - func mustGetTestBech32Address(hrp string) string { outAddr, err := bech32.ConvertAndEncode(hrp, utils.GenerateAccAddressForTest()) if err != nil { @@ -126,7 +92,7 @@ func mustGetTestBech32Address(hrp string) string { return outAddr } -func (s *KeeperTestSuite) TestHandleQueuedUnbondings() { +func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() { tests := []struct { name string records func(ctx sdk.Context, qs *app.Quicksilver, zone *icstypes.Zone) []icstypes.WithdrawalRecord @@ -401,16 +367,16 @@ func (s *KeeperTestSuite) TestHandleQueuedUnbondings() { } for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(test.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } records := test.records(ctx, quicksilver, &zone) delegations := test.delegations(ctx, quicksilver, &zone) @@ -424,7 +390,7 @@ func (s *KeeperTestSuite) TestHandleQueuedUnbondings() { for _, delegation := range delegations { quicksilver.InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) valAddrBytes, err := utils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) - s.Require().NoError(err) + suite.Require().NoError(err) val, _ := quicksilver.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) val.VotingPower = val.VotingPower.Add(delegation.Amount.Amount) val.DelegatorShares = val.DelegatorShares.Add(sdk.NewDecFromInt(delegation.Amount.Amount)) @@ -439,27 +405,27 @@ func (s *KeeperTestSuite) TestHandleQueuedUnbondings() { // trigger handler err := quicksilver.InterchainstakingKeeper.HandleQueuedUnbondings(ctx, &zone, 1) if test.expectError { - s.Require().Error(err) + suite.Require().Error(err) } else { - s.Require().NoError(err) + suite.Require().NoError(err) } for idx, record := range records { // check record with old status is opposite to expectedTransition (if false, this record should exist in status 3) _, found := quicksilver.InterchainstakingKeeper.GetWithdrawalRecord(ctx, zone.ChainId, record.Txhash, icskeeper.WithdrawStatusQueued) - s.Require().Equal(!test.expectTransition[idx], found) + suite.Require().Equal(!test.expectTransition[idx], found) // check record with new status is as per expectedTransition (if false, this record should not exist in status 4) _, found = quicksilver.InterchainstakingKeeper.GetWithdrawalRecord(ctx, zone.ChainId, record.Txhash, icskeeper.WithdrawStatusUnbond) - s.Require().Equal(test.expectTransition[idx], found) + suite.Require().Equal(test.expectTransition[idx], found) if test.expectTransition[idx] { actualRecord, found := quicksilver.InterchainstakingKeeper.GetWithdrawalRecord(ctx, zone.ChainId, record.Txhash, icskeeper.WithdrawStatusUnbond) - s.Require().True(found) + suite.Require().True(found) for _, unbonding := range actualRecord.Distribution { r, found := quicksilver.InterchainstakingKeeper.GetUnbondingRecord(ctx, zone.ChainId, unbonding.Valoper, 1) fmt.Println(r) - s.Require().True(found) - s.Require().Contains(r.RelatedTxhash, record.Txhash) + suite.Require().True(found) + suite.Require().Contains(r.RelatedTxhash, record.Txhash) } } } @@ -467,7 +433,7 @@ func (s *KeeperTestSuite) TestHandleQueuedUnbondings() { } } -func (s *KeeperTestSuite) TestHandleWithdrawForUser() { +func (suite *KeeperTestSuite) TestHandleWithdrawForUser() { tests := []struct { name string records func(zone *icstypes.Zone) []icstypes.WithdrawalRecord @@ -572,16 +538,16 @@ func (s *KeeperTestSuite) TestHandleWithdrawForUser() { } for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(test.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } records := test.records(&zone) @@ -590,29 +556,29 @@ func (s *KeeperTestSuite) TestHandleWithdrawForUser() { for _, record := range records { quicksilver.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record) err := quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(record.BurnAmount)) - s.Require().NoError(err) + suite.Require().NoError(err) err = quicksilver.BankKeeper.SendCoinsFromModuleToModule(ctx, icstypes.ModuleName, icstypes.EscrowModuleAccount, sdk.NewCoins(record.BurnAmount)) - s.Require().NoError(err) + suite.Require().NoError(err) } // trigger handler err := quicksilver.InterchainstakingKeeper.HandleWithdrawForUser(ctx, &zone, &test.message, test.memo) if test.err { - s.Require().Error(err) + suite.Require().Error(err) } else { - s.Require().NoError(err) + suite.Require().NoError(err) } quicksilver.InterchainstakingKeeper.IterateZoneStatusWithdrawalRecords(ctx, zone.ChainId, icskeeper.WithdrawStatusSend, func(idx int64, withdrawal icstypes.WithdrawalRecord) bool { if withdrawal.Txhash == test.memo { - s.Require().Fail("unexpected withdrawal record; status should be Completed.") + suite.Require().Fail("unexpected withdrawal record; status should be Completed.") } return false }) quicksilver.InterchainstakingKeeper.IterateZoneStatusWithdrawalRecords(ctx, zone.ChainId, icskeeper.WithdrawStatusCompleted, func(idx int64, withdrawal icstypes.WithdrawalRecord) bool { if withdrawal.Txhash != test.memo { - s.Require().Fail("unexpected withdrawal record; status should be Completed.") + suite.Require().Fail("unexpected withdrawal record; status should be Completed.") } return false }) @@ -620,7 +586,7 @@ func (s *KeeperTestSuite) TestHandleWithdrawForUser() { } } -func (s *KeeperTestSuite) TestHandleWithdrawForUserLSM() { +func (suite *KeeperTestSuite) TestHandleWithdrawForUserLSM() { v1 := utils.GenerateValAddressForTest().String() v2 := utils.GenerateValAddressForTest().String() tests := []struct { @@ -685,16 +651,16 @@ func (s *KeeperTestSuite) TestHandleWithdrawForUserLSM() { } for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(test.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } records := test.records(&zone) @@ -704,56 +670,56 @@ func (s *KeeperTestSuite) TestHandleWithdrawForUserLSM() { for _, record := range records { quicksilver.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record) err := quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(record.BurnAmount)) - s.Require().NoError(err) + suite.Require().NoError(err) err = quicksilver.BankKeeper.SendCoinsFromModuleToModule(ctx, icstypes.ModuleName, icstypes.EscrowModuleAccount, sdk.NewCoins(record.BurnAmount)) - s.Require().NoError(err) + suite.Require().NoError(err) } // trigger handler for i := range test.message { err := quicksilver.InterchainstakingKeeper.HandleWithdrawForUser(ctx, &zone, &test.message[i], test.memo) if test.err { - s.Require().Error(err) + suite.Require().Error(err) } else { - s.Require().NoError(err) + suite.Require().NoError(err) } } quicksilver.InterchainstakingKeeper.IterateZoneStatusWithdrawalRecords(ctx, zone.ChainId, icskeeper.WithdrawStatusSend, func(idx int64, withdrawal icstypes.WithdrawalRecord) bool { if withdrawal.Txhash == test.memo { - s.Require().Fail("unexpected withdrawal record; status should be Completed.") + suite.Require().Fail("unexpected withdrawal record; status should be Completed.") } return false }) quicksilver.InterchainstakingKeeper.IterateZoneStatusWithdrawalRecords(ctx, zone.ChainId, icskeeper.WithdrawStatusCompleted, func(idx int64, withdrawal icstypes.WithdrawalRecord) bool { if withdrawal.Txhash != test.memo { - s.Require().Fail("unexpected withdrawal record; status should be Completed.") + suite.Require().Fail("unexpected withdrawal record; status should be Completed.") } return false }) postBurnBalance := quicksilver.BankKeeper.GetAllBalances(ctx, quicksilver.AccountKeeper.GetModuleAddress(icstypes.ModuleName)) - s.Require().Equal(startBalance, postBurnBalance) + suite.Require().Equal(startBalance, postBurnBalance) }) } } -func (s *KeeperTestSuite) TestReceiveAckErrForBeginRedelegate() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestReceiveAckErrForBeginRedelegate() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } validators := quicksilver.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) // create redelegation record record := icstypes.RedelegationRecord{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, EpochNumber: 1, Source: validators[0].ValoperAddress, Destination: validators[1].ValoperAddress, @@ -764,7 +730,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginRedelegate() { redelegate := &stakingtypes.MsgBeginRedelegate{DelegatorAddress: zone.DelegationAddress.Address, ValidatorSrcAddress: validators[0].ValoperAddress, ValidatorDstAddress: validators[1].ValoperAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} data, err := icatypes.SerializeCosmosTx(quicksilver.InterchainstakingKeeper.GetCodec(), []sdk.Msg{redelegate}) - s.Require().NoError(err) + suite.Require().NoError(err) // validate memo < 256 bytes packetData := icatypes.InterchainAccountPacketData{ @@ -779,16 +745,16 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginRedelegate() { // call handler _, found = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, validators[0].ValoperAddress, validators[1].ValoperAddress, 1) - s.Require().True(found) + suite.Require().True(found) err = quicksilver.InterchainstakingKeeper.HandleAcknowledgement(ctx, packet, ackBytes) - s.Require().NoError(err) + suite.Require().NoError(err) _, found = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, validators[0].ValoperAddress, validators[1].ValoperAddress, 1) - s.Require().False(found) + suite.Require().False(found) } -func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { +func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { hash1 := fmt.Sprintf("%x", sha256.Sum256([]byte{0x01})) hash2 := fmt.Sprintf("%x", sha256.Sum256([]byte{0x02})) hash3 := fmt.Sprintf("%x", sha256.Sum256([]byte{0x03})) @@ -810,7 +776,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId) return []icstypes.WithdrawalRecord{ { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: []*icstypes.Distribution{ { @@ -834,7 +800,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId) return []icstypes.UnbondingRecord{ { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, EpochNumber: 1, Validator: vals[0], RelatedTxhash: []string{hash1}, @@ -855,7 +821,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId) return []icstypes.WithdrawalRecord{ { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: []*icstypes.Distribution{ { @@ -870,7 +836,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Status: icskeeper.WithdrawStatusUnbond, }, { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: nil, Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), @@ -889,7 +855,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId) return []icstypes.WithdrawalRecord{ { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: []*icstypes.Distribution{ { @@ -909,7 +875,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId) return []icstypes.UnbondingRecord{ { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, EpochNumber: 1, Validator: vals[0], RelatedTxhash: []string{hash1}, @@ -929,7 +895,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { expectedWithdrawalRecords: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { return []icstypes.WithdrawalRecord{ { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: nil, Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), @@ -948,7 +914,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId) return []icstypes.WithdrawalRecord{ { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: []*icstypes.Distribution{ { @@ -967,7 +933,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Status: icskeeper.WithdrawStatusUnbond, }, { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator2, Distribution: []*icstypes.Distribution{ { @@ -986,7 +952,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Status: icskeeper.WithdrawStatusUnbond, }, { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: []*icstypes.Distribution{ { @@ -1010,7 +976,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId) return []icstypes.UnbondingRecord{ { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, EpochNumber: 2, Validator: vals[1], RelatedTxhash: []string{hash1, hash2, hash3}, @@ -1031,7 +997,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId) return []icstypes.WithdrawalRecord{ { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: []*icstypes.Distribution{ { @@ -1046,7 +1012,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Status: icskeeper.WithdrawStatusUnbond, }, { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator2, Distribution: []*icstypes.Distribution{ { @@ -1061,7 +1027,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Status: icskeeper.WithdrawStatusUnbond, }, { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: []*icstypes.Distribution{ { @@ -1076,7 +1042,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Status: icskeeper.WithdrawStatusUnbond, }, { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: nil, Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), @@ -1086,7 +1052,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Status: icskeeper.WithdrawStatusQueued, }, { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator2, Distribution: nil, Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), @@ -1096,7 +1062,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Status: icskeeper.WithdrawStatusQueued, }, { - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: nil, Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), @@ -1233,16 +1199,16 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { } for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(test.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } for _, wdr := range test.withdrawalRecords(ctx, quicksilver, zone) { @@ -1254,7 +1220,7 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { } data, err := icatypes.SerializeCosmosTx(quicksilver.InterchainstakingKeeper.GetCodec(), test.msgs(ctx, quicksilver, zone)) - s.Require().NoError(err) + suite.Require().NoError(err) // validate memo < 256 bytes packetData := icatypes.InterchainAccountPacketData{ @@ -1270,41 +1236,41 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { for _, ubr := range test.unbondingRecords(ctx, quicksilver, zone) { _, found = quicksilver.InterchainstakingKeeper.GetUnbondingRecord(ctx, zone.ChainId, ubr.Validator, test.epoch) - s.Require().True(found) + suite.Require().True(found) } err = quicksilver.InterchainstakingKeeper.HandleAcknowledgement(ctx, packet, ackBytes) - s.Require().NoError(err) + suite.Require().NoError(err) for _, ubr := range test.unbondingRecords(ctx, quicksilver, zone) { _, found = quicksilver.InterchainstakingKeeper.GetUnbondingRecord(ctx, zone.ChainId, ubr.Validator, test.epoch) - s.Require().False(found) + suite.Require().False(found) } for idx, ewdr := range test.expectedWithdrawalRecords(ctx, quicksilver, zone) { wdr, found := quicksilver.InterchainstakingKeeper.GetWithdrawalRecord(ctx, zone.ChainId, ewdr.Txhash, ewdr.Status) - s.Require().True(found) - s.Require().Equal(ewdr.Amount, wdr.Amount) - s.Require().Equal(ewdr.BurnAmount, wdr.BurnAmount) - s.Require().Equal(ewdr.Delegator, wdr.Delegator) - s.Require().Equal(ewdr.Distribution, wdr.Distribution, idx) - s.Require().Equal(ewdr.Status, wdr.Status) + suite.Require().True(found) + suite.Require().Equal(ewdr.Amount, wdr.Amount) + suite.Require().Equal(ewdr.BurnAmount, wdr.BurnAmount) + suite.Require().Equal(ewdr.Delegator, wdr.Delegator) + suite.Require().Equal(ewdr.Distribution, wdr.Distribution, idx) + suite.Require().Equal(ewdr.Status, wdr.Status) } }) } } -func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestRebalanceDueToIntentChange() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } vals := quicksilver.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) for _, val := range vals { @@ -1352,7 +1318,7 @@ func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { for _, delegation := range delegations { quicksilver.InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) addressBytes, err := utils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) - s.Require().NoError(err) + suite.Require().NoError(err) val, _ := quicksilver.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, addressBytes) val.VotingPower = val.VotingPower.Add(delegation.Amount.Amount) val.DelegatorShares = val.DelegatorShares.Add(sdk.NewDecFromInt(delegation.Amount.Amount)) @@ -1362,7 +1328,7 @@ func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { // trigger rebalance err := quicksilver.InterchainstakingKeeper.Rebalance(ctx, &zone, 1) - s.Require().NoError(err) + suite.Require().NoError(err) // change intents to trigger redelegations from val[3] intents := icstypes.ValidatorIntents{ @@ -1375,7 +1341,7 @@ func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { // trigger rebalance err = quicksilver.InterchainstakingKeeper.Rebalance(ctx, &zone, 2) - s.Require().NoError(err) + suite.Require().NoError(err) // mock ack for redelegations quicksilver.InterchainstakingKeeper.IteratePrefixedRedelegationRecords(ctx, []byte(zone.ChainId), func(idx int64, _ []byte, record icstypes.RedelegationRecord) (stop bool) { @@ -1396,14 +1362,14 @@ func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { // check for redelegations _, present := quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, vals[3].ValoperAddress, vals[0].ValoperAddress, 2) - s.Require().True(present) + suite.Require().True(present) _, present = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, vals[3].ValoperAddress, vals[1].ValoperAddress, 2) - s.Require().True(present) + suite.Require().True(present) _, present = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, vals[3].ValoperAddress, vals[2].ValoperAddress, 2) - s.Require().True(present) + suite.Require().True(present) // change intents to trigger transitive redelegations which should fail rebalance - zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ = quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) intents = icstypes.ValidatorIntents{ {ValoperAddress: vals[0].ValoperAddress, Weight: sdk.NewDecWithPrec(1, 1)}, {ValoperAddress: vals[1].ValoperAddress, Weight: sdk.NewDecWithPrec(3, 1)}, @@ -1414,27 +1380,27 @@ func (s *KeeperTestSuite) TestRebalanceDueToIntentChange() { // trigger rebalance err = quicksilver.InterchainstakingKeeper.Rebalance(ctx, &zone, 3) - s.Require().NoError(err) + suite.Require().NoError(err) // check for redelegations originating from val[0], they should not be present _, present = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, vals[0].ValoperAddress, vals[1].ValoperAddress, 3) - s.Require().False(present) + suite.Require().False(present) _, present = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, vals[0].ValoperAddress, vals[2].ValoperAddress, 3) - s.Require().False(present) + suite.Require().False(present) _, present = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, vals[0].ValoperAddress, vals[3].ValoperAddress, 3) - s.Require().False(present) + suite.Require().False(present) } -func (s *KeeperTestSuite) TestRebalanceDueToDelegationChange() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestRebalanceDueToDelegationChange() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } vals := quicksilver.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) for _, val := range vals { @@ -1479,11 +1445,11 @@ func (s *KeeperTestSuite) TestRebalanceDueToDelegationChange() { for _, delegation := range delegations { quicksilver.InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) valAddrBytes, err := utils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) - s.Require().NoError(err) + suite.Require().NoError(err) val, found := quicksilver.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) - s.Require().NoError(err) - s.Require().True(found) + suite.Require().NoError(err) + suite.Require().True(found) val.VotingPower = val.VotingPower.Add(delegation.Amount.Amount) val.DelegatorShares = val.DelegatorShares.Add(sdk.NewDecFromInt(delegation.Amount.Amount)) @@ -1491,7 +1457,7 @@ func (s *KeeperTestSuite) TestRebalanceDueToDelegationChange() { // trigger rebalance err := quicksilver.InterchainstakingKeeper.Rebalance(ctx, &zone, 1) - s.Require().NoError(err) + suite.Require().NoError(err) quicksilver.InterchainstakingKeeper.IterateAllDelegations(ctx, &zone, func(delegation icstypes.Delegation) bool { if delegation.ValidatorAddress == val0.ValoperAddress { @@ -1503,7 +1469,7 @@ func (s *KeeperTestSuite) TestRebalanceDueToDelegationChange() { // trigger rebalance err = quicksilver.InterchainstakingKeeper.Rebalance(ctx, &zone, 2) - s.Require().NoError(err) + suite.Require().NoError(err) // mock ack for redelegations quicksilver.InterchainstakingKeeper.IteratePrefixedRedelegationRecords(ctx, []byte(zone.ChainId), func(idx int64, _ []byte, record icstypes.RedelegationRecord) (stop bool) { @@ -1526,9 +1492,9 @@ func (s *KeeperTestSuite) TestRebalanceDueToDelegationChange() { // check for redelegations _, present := quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, val0.ValoperAddress, val1.ValoperAddress, 2) - s.Require().False(present) + suite.Require().False(present) _, present = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, val0.ValoperAddress, val2.ValoperAddress, 2) - s.Require().False(present) + suite.Require().False(present) // change validator delegation to trigger transitive redelegations which should fail rebalance quicksilver.InterchainstakingKeeper.IterateAllDelegations(ctx, &zone, func(delegation icstypes.Delegation) bool { @@ -1546,18 +1512,18 @@ func (s *KeeperTestSuite) TestRebalanceDueToDelegationChange() { // trigger rebalance err = quicksilver.InterchainstakingKeeper.Rebalance(ctx, &zone, 3) - s.Require().NoError(err) + suite.Require().NoError(err) // check for redelegations originating from val[1], they should not be present _, present = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, val1.ValoperAddress, val0.ValoperAddress, 3) - s.Require().False(present) + suite.Require().False(present) _, present = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, val1.ValoperAddress, val1.ValoperAddress, 3) - s.Require().False(present) + suite.Require().False(present) _, present = quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, zone.ChainId, val1.ValoperAddress, val3.ValoperAddress, 3) - s.Require().False(present) + suite.Require().False(present) } -func (s *KeeperTestSuite) Test_v045Callback() { +func (suite *KeeperTestSuite) Test_v045Callback() { tests := []struct { name string setStatements func(ctx sdk.Context, quicksilver *app.Quicksilver) ([]sdk.Msg, []byte) @@ -1567,10 +1533,10 @@ func (s *KeeperTestSuite) Test_v045Callback() { name: "msg response with some data", setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) ([]sdk.Msg, []byte) { err := quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("denom", sdk.NewInt(100)))) - s.Require().NoError(err) + suite.Require().NoError(err) sender := utils.GenerateAccAddressForTest() senderAddr, err := sdk.Bech32ifyAddressBytes("cosmos", sender) - s.Require().NoError(err) + suite.Require().NoError(err) transferMsg := ibctransfertypes.MsgTransfer{ SourcePort: "transfer", @@ -1603,9 +1569,9 @@ func (s *KeeperTestSuite) Test_v045Callback() { { name: "msg response with nil data", setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) ([]sdk.Msg, []byte) { - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } msgSetWithdrawAddress := distrtypes.MsgSetWithdrawAddress{ @@ -1619,9 +1585,9 @@ func (s *KeeperTestSuite) Test_v045Callback() { return []sdk.Msg{&msgSetWithdrawAddress}, respBytes }, assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } // assert that withdraw address is set if zone.WithdrawalAddress.Address == zone.PerformanceAddress.WithdrawalAddress { @@ -1633,12 +1599,12 @@ func (s *KeeperTestSuite) Test_v045Callback() { } for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(test.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() msg, msgResponseBytes := test.setStatements(ctx, quicksilver) @@ -1657,7 +1623,7 @@ func (s *KeeperTestSuite) Test_v045Callback() { } pdBytes, err := icatypes.SerializeCosmosTx(icatypes.ModuleCdc, msg) - s.Require().NoError(err) + suite.Require().NoError(err) packetData := icatypes.InterchainAccountPacketData{ Type: icatypes.EXECUTE_TX, Data: pdBytes, @@ -1665,19 +1631,19 @@ func (s *KeeperTestSuite) Test_v045Callback() { } packetBytes, err := icatypes.ModuleCdc.MarshalJSON(&packetData) - s.Require().NoError(err) + suite.Require().NoError(err) packet := channeltypes.Packet{ Data: packetBytes, } - s.Require().NoError(quicksilver.InterchainstakingKeeper.HandleAcknowledgement(ctx, packet, icatypes.ModuleCdc.MustMarshalJSON(&acknowledgement))) + suite.Require().NoError(quicksilver.InterchainstakingKeeper.HandleAcknowledgement(ctx, packet, icatypes.ModuleCdc.MustMarshalJSON(&acknowledgement))) - s.Require().True(test.assertStatements(ctx, quicksilver)) + suite.Require().True(test.assertStatements(ctx, quicksilver)) }) } } -func (s *KeeperTestSuite) Test_v046Callback() { +func (suite *KeeperTestSuite) Test_v046Callback() { tests := []struct { name string setStatements func(ctx sdk.Context, quicksilver *app.Quicksilver) ([]sdk.Msg, *codectypes.Any) @@ -1687,10 +1653,10 @@ func (s *KeeperTestSuite) Test_v046Callback() { name: "msg response with some data", setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) ([]sdk.Msg, *codectypes.Any) { err := quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("denom", sdk.NewInt(100)))) - s.Require().NoError(err) + suite.Require().NoError(err) sender := utils.GenerateAccAddressForTest() senderAddr, err := sdk.Bech32ifyAddressBytes("cosmos", sender) - s.Require().NoError(err) + suite.Require().NoError(err) transferMsg := ibctransfertypes.MsgTransfer{ SourcePort: "transfer", @@ -1704,7 +1670,7 @@ func (s *KeeperTestSuite) Test_v046Callback() { } anyResponse, err := codectypes.NewAnyWithValue(&response) - s.Require().NoError(err) + suite.Require().NoError(err) return []sdk.Msg{&transferMsg}, anyResponse }, assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { @@ -1724,9 +1690,9 @@ func (s *KeeperTestSuite) Test_v046Callback() { { name: "msg response with nil data", setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) ([]sdk.Msg, *codectypes.Any) { - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } msgSetWithdrawAddress := distrtypes.MsgSetWithdrawAddress{ @@ -1737,13 +1703,13 @@ func (s *KeeperTestSuite) Test_v046Callback() { response := distrtypes.MsgSetWithdrawAddressResponse{} anyResponse, err := codectypes.NewAnyWithValue(&response) - s.Require().NoError(err) + suite.Require().NoError(err) return []sdk.Msg{&msgSetWithdrawAddress}, anyResponse }, assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool { - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) if !found { - s.Fail("unable to retrieve zone for test") + suite.Fail("unable to retrieve zone for test") } // assert that withdraw address is set if zone.WithdrawalAddress.Address == zone.PerformanceAddress.WithdrawalAddress { @@ -1755,12 +1721,12 @@ func (s *KeeperTestSuite) Test_v046Callback() { } for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(test.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() msg, anyResp := test.setStatements(ctx, quicksilver) @@ -1778,7 +1744,7 @@ func (s *KeeperTestSuite) Test_v046Callback() { } pdBytes, err := icatypes.SerializeCosmosTx(icatypes.ModuleCdc, msg) - s.Require().NoError(err) + suite.Require().NoError(err) packetData := icatypes.InterchainAccountPacketData{ Type: icatypes.EXECUTE_TX, Data: pdBytes, @@ -1786,14 +1752,14 @@ func (s *KeeperTestSuite) Test_v046Callback() { } packetBytes, err := icatypes.ModuleCdc.MarshalJSON(&packetData) - s.Require().NoError(err) + suite.Require().NoError(err) packet := channeltypes.Packet{ Data: packetBytes, } - s.Require().NoError(quicksilver.InterchainstakingKeeper.HandleAcknowledgement(ctx, packet, icatypes.ModuleCdc.MustMarshalJSON(&acknowledgement))) + suite.Require().NoError(quicksilver.InterchainstakingKeeper.HandleAcknowledgement(ctx, packet, icatypes.ModuleCdc.MustMarshalJSON(&acknowledgement))) - s.Require().True(test.assertStatements(ctx, quicksilver)) + suite.Require().True(test.assertStatements(ctx, quicksilver)) }) } } diff --git a/x/interchainstaking/keeper/intent_test.go b/x/interchainstaking/keeper/intent_test.go index 8edbf4e0a..a01ecaf0c 100644 --- a/x/interchainstaking/keeper/intent_test.go +++ b/x/interchainstaking/keeper/intent_test.go @@ -14,21 +14,21 @@ var ( user2 = utils.GenerateAccAddressForTest() ) -func (s *KeeperTestSuite) TestKeeper_IntentStore() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestKeeper_IntentStore() { + suite.SetupTest() + suite.setupTestZones() - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() // get test zone - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) zoneValidatorAddresses := icsKeeper.GetValidators(ctx, zone.ChainId) // check that there are no intents intents := icsKeeper.AllDelegatorIntents(ctx, &zone, false) - s.Require().Len(intents, 0) + suite.Require().Len(intents, 0) // set intents for testAddress icsKeeper.SetDelegatorIntent( @@ -110,16 +110,16 @@ func (s *KeeperTestSuite) TestKeeper_IntentStore() { // check for intents set above intents = icsKeeper.AllDelegatorIntents(ctx, &zone, false) - s.Require().Len(intents, 3) + suite.Require().Len(intents, 3) // delete intent for testAddress icsKeeper.DeleteDelegatorIntent(ctx, &zone, testAddress, false) // check intents intents = icsKeeper.AllDelegatorIntents(ctx, &zone, false) - s.Require().Len(intents, 2) + suite.Require().Len(intents, 2) - s.T().Logf("intents:\n%+v\n", intents) + suite.T().Logf("intents:\n%+v\n", intents) // update intent for user1 err := icsKeeper.UpdateDelegatorIntent( @@ -134,18 +134,18 @@ func (s *KeeperTestSuite) TestKeeper_IntentStore() { ), nil, ) - s.Require().NoError(err) + suite.Require().NoError(err) // load and match pointers intentsPointers := icsKeeper.AllDelegatorIntentsAsPointer(ctx, &zone, false) for i, ip := range intentsPointers { - s.Require().Equal(intents[i], *ip) + suite.Require().Equal(intents[i], *ip) } - s.T().Logf("intents:\n%+v\n", intentsPointers) + suite.T().Logf("intents:\n%+v\n", intentsPointers) } -func (s *KeeperTestSuite) TestAggregateIntent() { +func (suite *KeeperTestSuite) TestAggregateIntent() { tc := []struct { name string intents func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.DelegatorIntent @@ -314,19 +314,19 @@ func (s *KeeperTestSuite) TestAggregateIntent() { } for _, tt := range tc { - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() icsKeeper := quicksilver.InterchainstakingKeeper - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) // give each user some funds for addrString, balance := range tt.balances() { - s.giveFunds(ctx, zone.LocalDenom, balance, addrString) + suite.giveFunds(ctx, zone.LocalDenom, balance, addrString) } for _, intent := range tt.intents(ctx, quicksilver, zone) { @@ -336,17 +336,17 @@ func (s *KeeperTestSuite) TestAggregateIntent() { _ = icsKeeper.AggregateDelegatorIntents(ctx, &zone) // refresh zone to pull new aggregate - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) actual, err := icsKeeper.GetAggregateIntentOrDefault(ctx, &zone) - s.Require().NoError(err) - s.Require().Equal(tt.expected(ctx, quicksilver, zone), actual) + suite.Require().NoError(err) + suite.Require().Equal(tt.expected(ctx, quicksilver, zone), actual) }) } } -// func (s *KeeperTestSuite) TestAggregateIntentWithPRClaims() { +// func (suite *KeeperTestSuite) TestAggregateIntentWithPRClaims() { // tc := []struct { // name string // intents func(zone icstypes.Zone) []icstypes.DelegatorIntent @@ -423,21 +423,21 @@ func (s *KeeperTestSuite) TestAggregateIntent() { // } // for _, tt := range tc { -// s.Run(tt.name, func() { -// s.SetupTest() -// s.setupTestZones() +// suite.Run(tt.name, func() { +// suite.SetupTest() +// suite.setupTestZones() -// quicksilver := s.GetQuicksilverApp(s.chainA) -// ctx := s.chainA.GetContext() +// quicksilver := suite.GetQuicksilverApp(suite.chainA) +// ctx := suite.chainA.GetContext() // icsKeeper := quicksilver.InterchainstakingKeeper -// zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) -// s.Require().True(found) +// zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) +// suite.Require().True(found) // // give each user some funds // for addrString, balance := range tt.balances(zone.LocalDenom) { // quicksilver.MintKeeper.MintCoins(ctx, balance) // addr, err := utils.AccAddressFromBech32(addrString, "") -// s.Require().NoError(err) +// suite.Require().NoError(err) // quicksilver.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, balance) // } @@ -452,11 +452,11 @@ func (s *KeeperTestSuite) TestAggregateIntent() { // icsKeeper.AggregateDelegatorIntents(ctx, zone) // // refresh zone to pull new aggregate -// zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) -// s.Require().True(found) +// zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) +// suite.Require().True(found) // actual := zone.GetAggregateIntentOrDefault() -// s.Require().Equal(tt.expected(zone), actual) +// suite.Require().Equal(tt.expected(zone), actual) // }) // } // } diff --git a/x/interchainstaking/keeper/keeper_test.go b/x/interchainstaking/keeper/keeper_test.go index 3bfecbe77..42624786a 100644 --- a/x/interchainstaking/keeper/keeper_test.go +++ b/x/interchainstaking/keeper/keeper_test.go @@ -10,7 +10,7 @@ import ( minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" ibctesting "github.com/cosmos/ibc-go/v5/testing" - "github.com/stretchr/testify/suite" + testsuite "github.com/stretchr/testify/suite" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" @@ -34,7 +34,7 @@ func init() { // TestKeeperTestSuite runs all the tests within this package. func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(KeeperTestSuite)) + testsuite.Run(t, new(KeeperTestSuite)) } func newQuicksilverPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { @@ -46,7 +46,7 @@ func newQuicksilverPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { } type KeeperTestSuite struct { - suite.Suite + testsuite.Suite coordinator *ibctesting.Coordinator @@ -55,7 +55,7 @@ type KeeperTestSuite struct { path *ibctesting.Path } -func (s *KeeperTestSuite) GetQuicksilverApp(chain *ibctesting.TestChain) *app.Quicksilver { +func (suite *KeeperTestSuite) GetQuicksilverApp(chain *ibctesting.TestChain) *app.Quicksilver { quicksilver, ok := chain.App.(*app.Quicksilver) if !ok { panic("not quicksilver app") @@ -65,20 +65,20 @@ func (s *KeeperTestSuite) GetQuicksilverApp(chain *ibctesting.TestChain) *app.Qu } // SetupTest creates a coordinator with 2 test chains. -func (s *KeeperTestSuite) SetupTest() { - s.coordinator = ibctesting.NewCoordinator(s.T(), 2) // initializes 2 test chains - s.chainA = s.coordinator.GetChain(ibctesting.GetChainID(1)) // convenience and readability - s.chainB = s.coordinator.GetChain(ibctesting.GetChainID(2)) // convenience and readability +func (suite *KeeperTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) // initializes 2 test chains + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) // convenience and readability + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) // convenience and readability - s.path = newQuicksilverPath(s.chainA, s.chainB) - s.coordinator.SetupConnections(s.path) + suite.path = newQuicksilverPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(suite.path) } -func (s *KeeperTestSuite) setupTestZones() { +func (suite *KeeperTestSuite) setupTestZones() { proposal := &icstypes.RegisterZoneProposal{ Title: "register zone A", Description: "register zone A", - ConnectionId: s.path.EndpointA.ConnectionID, + ConnectionId: suite.path.EndpointA.ConnectionID, LocalDenom: "uqatom", BaseDenom: "uatom", AccountPrefix: "cosmos", @@ -89,36 +89,36 @@ func (s *KeeperTestSuite) setupTestZones() { Decimals: 6, } - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() err := quicksilver.InterchainstakingKeeper.HandleRegisterZoneProposal(ctx, proposal) - s.Require().NoError(err) + suite.Require().NoError(err) - zone, found := quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) - quicksilver.IBCKeeper.ClientKeeper.SetClientState(ctx, "07-tendermint-0", &tmclienttypes.ClientState{ChainId: s.chainB.ChainID, TrustingPeriod: time.Hour, LatestHeight: clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}}) + quicksilver.IBCKeeper.ClientKeeper.SetClientState(ctx, "07-tendermint-0", &tmclienttypes.ClientState{ChainId: suite.chainB.ChainID, TrustingPeriod: time.Hour, LatestHeight: clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}}) quicksilver.IBCKeeper.ClientKeeper.SetClientConsensusState(ctx, "07-tendermint-0", clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}, &tmclienttypes.ConsensusState{Timestamp: ctx.BlockTime()}) - quicksilver.IBCKeeper.ConnectionKeeper.SetConnection(ctx, s.path.EndpointA.ConnectionID, connectiontypes.ConnectionEnd{ClientId: "07-tendermint-0"}) - s.Require().NoError(s.setupChannelForICA(ctx, s.chainB.ChainID, s.path.EndpointA.ConnectionID, "deposit", zone.AccountPrefix)) - s.Require().NoError(s.setupChannelForICA(ctx, s.chainB.ChainID, s.path.EndpointA.ConnectionID, "withdrawal", zone.AccountPrefix)) - s.Require().NoError(s.setupChannelForICA(ctx, s.chainB.ChainID, s.path.EndpointA.ConnectionID, "performance", zone.AccountPrefix)) - s.Require().NoError(s.setupChannelForICA(ctx, s.chainB.ChainID, s.path.EndpointA.ConnectionID, "delegate", zone.AccountPrefix)) - zone, found = quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) - - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetBondedValidatorsByPower(s.chainB.GetContext()) + quicksilver.IBCKeeper.ConnectionKeeper.SetConnection(ctx, suite.path.EndpointA.ConnectionID, connectiontypes.ConnectionEnd{ClientId: "07-tendermint-0"}) + suite.Require().NoError(suite.setupChannelForICA(ctx, suite.chainB.ChainID, suite.path.EndpointA.ConnectionID, "deposit", zone.AccountPrefix)) + suite.Require().NoError(suite.setupChannelForICA(ctx, suite.chainB.ChainID, suite.path.EndpointA.ConnectionID, "withdrawal", zone.AccountPrefix)) + suite.Require().NoError(suite.setupChannelForICA(ctx, suite.chainB.ChainID, suite.path.EndpointA.ConnectionID, "performance", zone.AccountPrefix)) + suite.Require().NoError(suite.setupChannelForICA(ctx, suite.chainB.ChainID, suite.path.EndpointA.ConnectionID, "delegate", zone.AccountPrefix)) + zone, found = quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) + + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetBondedValidatorsByPower(suite.chainB.GetContext()) for i := range vals { - s.Require().NoError(quicksilver.InterchainstakingKeeper.SetValidatorForZone(s.chainA.GetContext(), &zone, app.DefaultConfig().Codec.MustMarshal(&vals[i]))) + suite.Require().NoError(quicksilver.InterchainstakingKeeper.SetValidatorForZone(suite.chainA.GetContext(), &zone, app.DefaultConfig().Codec.MustMarshal(&vals[i]))) } - s.coordinator.CommitNBlocks(s.chainA, 2) - s.coordinator.CommitNBlocks(s.chainB, 2) + suite.coordinator.CommitNBlocks(suite.chainA, 2) + suite.coordinator.CommitNBlocks(suite.chainB, 2) } -func (s *KeeperTestSuite) setupChannelForICA(ctx sdk.Context, chainID, connectionID, accountSuffix, remotePrefix string) error { - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) setupChannelForICA(ctx sdk.Context, chainID, connectionID, accountSuffix, remotePrefix string) error { + quicksilver := suite.GetQuicksilverApp(suite.chainA) ibcModule := ics.NewIBCModule(quicksilver.InterchainstakingKeeper) portID, err := icatypes.NewControllerPortID(chainID + "." + accountSuffix) @@ -177,8 +177,8 @@ func (s *KeeperTestSuite) setupChannelForICA(ctx sdk.Context, chainID, connectio return ibcModule.OnChanOpenAck(ctx, portID, channelID, "", "") } -func (s *KeeperTestSuite) giveFunds(ctx sdk.Context, denom string, amount int64, address string) { - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) giveFunds(ctx sdk.Context, denom string, amount int64, address string) { + quicksilver := suite.GetQuicksilverApp(suite.chainA) balance := sdk.NewCoins( sdk.NewCoin( @@ -187,14 +187,14 @@ func (s *KeeperTestSuite) giveFunds(ctx sdk.Context, denom string, amount int64, ), ) err := quicksilver.MintKeeper.MintCoins(ctx, balance) - s.Require().NoError(err) + suite.Require().NoError(err) addr, err := utils.AccAddressFromBech32(address, "") - s.Require().NoError(err) + suite.Require().NoError(err) err = quicksilver.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, balance) - s.Require().NoError(err) + suite.Require().NoError(err) } -func (s *KeeperTestSuite) TestGetDelegatedAmount() { +func (suite *KeeperTestSuite) TestGetDelegatedAmount() { tc := []struct { name string delegations func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.Delegation @@ -235,28 +235,28 @@ func (s *KeeperTestSuite) TestGetDelegatedAmount() { } for _, tt := range tc { - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() icsKeeper := quicksilver.InterchainstakingKeeper - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) for _, delegation := range tt.delegations(ctx, quicksilver, zone) { icsKeeper.SetDelegation(ctx, &zone, delegation) } actual := icsKeeper.GetDelegatedAmount(ctx, &zone) - s.Require().Equal(tt.expected, actual.Amount) - s.Require().Equal(zone.BaseDenom, actual.Denom) + suite.Require().Equal(tt.expected, actual.Amount) + suite.Require().Equal(zone.BaseDenom, actual.Denom) }) } } -func (s *KeeperTestSuite) TestGetUnbondingAmount() { +func (suite *KeeperTestSuite) TestGetUnbondingAmount() { tc := []struct { name string records func(zone icstypes.Zone) []icstypes.WithdrawalRecord @@ -317,28 +317,28 @@ func (s *KeeperTestSuite) TestGetUnbondingAmount() { } for _, tt := range tc { - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() icsKeeper := quicksilver.InterchainstakingKeeper - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) for _, record := range tt.records(zone) { icsKeeper.SetWithdrawalRecord(ctx, record) } actual := icsKeeper.GetUnbondingAmount(ctx, &zone) - s.Require().Equal(tt.expected, actual.Amount) - s.Require().Equal(zone.BaseDenom, actual.Denom) + suite.Require().Equal(tt.expected, actual.Amount) + suite.Require().Equal(zone.BaseDenom, actual.Denom) }) } } -func (s *KeeperTestSuite) TestGetRatio() { +func (suite *KeeperTestSuite) TestGetRatio() { tc := []struct { name string records func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord @@ -482,15 +482,15 @@ func (s *KeeperTestSuite) TestGetRatio() { } for _, tt := range tc { - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() icsKeeper := quicksilver.InterchainstakingKeeper - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) for _, record := range tt.records(ctx, quicksilver, zone) { icsKeeper.SetWithdrawalRecord(ctx, record) @@ -501,26 +501,26 @@ func (s *KeeperTestSuite) TestGetRatio() { } err := quicksilver.MintKeeper.MintCoins(ctx, sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, tt.supply))) - s.Require().NoError(err) + suite.Require().NoError(err) actual, isZero := icsKeeper.GetRatio(ctx, &zone, sdk.ZeroInt()) - s.Require().Equal(tt.supply.IsZero(), isZero) - s.Require().Equal(tt.expected, actual) + suite.Require().Equal(tt.supply.IsZero(), isZero) + suite.Require().Equal(tt.expected, actual) }) } } -func (s *KeeperTestSuite) TestUpdateRedemptionRate() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestUpdateRedemptionRate() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() icsKeeper := quicksilver.InterchainstakingKeeper - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -530,18 +530,18 @@ func (s *KeeperTestSuite) TestUpdateRedemptionRate() { icsKeeper.SetDelegation(ctx, &zone, delegationC) err := quicksilver.MintKeeper.MintCoins(ctx, sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewInt(3000)))) - s.Require().NoError(err) + suite.Require().NoError(err) // no change! - s.Require().Equal(sdk.OneDec(), zone.RedemptionRate) + suite.Require().Equal(sdk.OneDec(), zone.RedemptionRate) icsKeeper.UpdateRedemptionRate(ctx, &zone, sdk.ZeroInt()) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - s.Require().Equal(sdk.OneDec(), zone.RedemptionRate) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + suite.Require().Equal(sdk.OneDec(), zone.RedemptionRate) // add 1% - s.Require().Equal(sdk.OneDec(), zone.RedemptionRate) + suite.Require().Equal(sdk.OneDec(), zone.RedemptionRate) icsKeeper.UpdateRedemptionRate(ctx, &zone, sdk.NewInt(30)) delegationA.Amount.Amount = delegationA.Amount.Amount.AddRaw(10) delegationB.Amount.Amount = delegationB.Amount.Amount.AddRaw(10) @@ -550,9 +550,9 @@ func (s *KeeperTestSuite) TestUpdateRedemptionRate() { icsKeeper.SetDelegation(ctx, &zone, delegationB) icsKeeper.SetDelegation(ctx, &zone, delegationC) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(101, 2), zone.RedemptionRate) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + suite.Require().Equal(sdk.NewDecWithPrec(101, 2), zone.RedemptionRate) // add >2%; cap at 2% icsKeeper.UpdateRedemptionRate(ctx, &zone, sdk.NewInt(500)) @@ -562,17 +562,17 @@ func (s *KeeperTestSuite) TestUpdateRedemptionRate() { icsKeeper.SetDelegation(ctx, &zone, delegationA) icsKeeper.SetDelegation(ctx, &zone, delegationB) icsKeeper.SetDelegation(ctx, &zone, delegationC) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) // should be capped at 2% increase. (1.01*1.02 == 1.0302) - s.Require().Equal(sdk.NewDecWithPrec(10302, 4), zone.RedemptionRate) + suite.Require().Equal(sdk.NewDecWithPrec(10302, 4), zone.RedemptionRate) // add nothing, still cap at 2% icsKeeper.UpdateRedemptionRate(ctx, &zone, sdk.ZeroInt()) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) // should be capped at 2% increase. (1.01*1.02*1.02 == 1.050804) - s.Require().Equal(sdk.NewDecWithPrec(1050804, 6), zone.RedemptionRate) + suite.Require().Equal(sdk.NewDecWithPrec(1050804, 6), zone.RedemptionRate) delegationA.Amount.Amount = delegationA.Amount.Amount.SubRaw(500) delegationB.Amount.Amount = delegationB.Amount.Amount.SubRaw(500) @@ -583,23 +583,23 @@ func (s *KeeperTestSuite) TestUpdateRedemptionRate() { // remove > 5%, cap at -5% icsKeeper.UpdateRedemptionRate(ctx, &zone, sdk.ZeroInt()) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(9982638, 7), zone.RedemptionRate) + suite.Require().Equal(sdk.NewDecWithPrec(9982638, 7), zone.RedemptionRate) } -func (s *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() icsKeeper := quicksilver.InterchainstakingKeeper - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -609,15 +609,15 @@ func (s *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { icsKeeper.SetDelegation(ctx, &zone, delegationC) err := quicksilver.MintKeeper.MintCoins(ctx, sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewInt(3000)))) - s.Require().NoError(err) + suite.Require().NoError(err) // no change! - s.Require().Equal(sdk.OneDec(), zone.RedemptionRate) + suite.Require().Equal(sdk.OneDec(), zone.RedemptionRate) icsKeeper.OverrideRedemptionRateNoCap(ctx, &zone) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - s.Require().Equal(sdk.OneDec(), zone.RedemptionRate) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + suite.Require().Equal(sdk.OneDec(), zone.RedemptionRate) // add 1% delegationA.Amount.Amount = delegationA.Amount.Amount.AddRaw(10) @@ -628,9 +628,9 @@ func (s *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { icsKeeper.SetDelegation(ctx, &zone, delegationC) icsKeeper.OverrideRedemptionRateNoCap(ctx, &zone) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(101, 2), zone.RedemptionRate) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + suite.Require().Equal(sdk.NewDecWithPrec(101, 2), zone.RedemptionRate) // add >2%; no cap delegationA.Amount.Amount = delegationA.Amount.Amount.AddRaw(166) @@ -641,15 +641,15 @@ func (s *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { icsKeeper.SetDelegation(ctx, &zone, delegationC) icsKeeper.OverrideRedemptionRateNoCap(ctx, &zone) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(1176666666666666667, 18), zone.RedemptionRate) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + suite.Require().Equal(sdk.NewDecWithPrec(1176666666666666667, 18), zone.RedemptionRate) // add nothing, no change icsKeeper.OverrideRedemptionRateNoCap(ctx, &zone) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(1176666666666666667, 18), zone.RedemptionRate) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + suite.Require().Equal(sdk.NewDecWithPrec(1176666666666666667, 18), zone.RedemptionRate) delegationA.Amount.Amount = delegationA.Amount.Amount.SubRaw(500) delegationB.Amount.Amount = delegationB.Amount.Amount.SubRaw(500) @@ -658,8 +658,8 @@ func (s *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { icsKeeper.SetDelegation(ctx, &zone, delegationB) icsKeeper.SetDelegation(ctx, &zone, delegationC) icsKeeper.OverrideRedemptionRateNoCap(ctx, &zone) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(676666666666666667, 18), zone.RedemptionRate) + suite.Require().Equal(sdk.NewDecWithPrec(676666666666666667, 18), zone.RedemptionRate) } diff --git a/x/interchainstaking/keeper/msg_server_test.go b/x/interchainstaking/keeper/msg_server_test.go index 42d49121b..45b1ee3d1 100644 --- a/x/interchainstaking/keeper/msg_server_test.go +++ b/x/interchainstaking/keeper/msg_server_test.go @@ -13,11 +13,11 @@ import ( icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -func (s *KeeperTestSuite) TestRequestRedemption() { +func (suite *KeeperTestSuite) TestRequestRedemption() { var msg icstypes.MsgRequestRedemption testAccount, err := utils.AccAddressFromBech32(testAddress, "") - s.Require().NoError(err) + suite.Require().NoError(err) tests := []struct { name string @@ -29,7 +29,7 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "valid - full claim", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), DestinationAddress: addr, @@ -43,17 +43,17 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "valid - full claim (discounted)", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.RedemptionRate = sdk.MustNewDecFromStr("0.95") - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "", "", @@ -62,18 +62,18 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "valid - full claim (interest)", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.LastRedemptionRate = sdk.MustNewDecFromStr("1.05") zone.RedemptionRate = sdk.MustNewDecFromStr("1.1") - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "", "", @@ -82,18 +82,18 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "valid - full claim (interest)", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.LastRedemptionRate = sdk.MustNewDecFromStr("1.1") zone.RedemptionRate = sdk.MustNewDecFromStr("1.05") - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "", "", @@ -102,7 +102,7 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "valid - partial claim", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), DestinationAddress: addr, @@ -116,17 +116,17 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "valid - partial claim (discounted)", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.RedemptionRate = sdk.MustNewDecFromStr("0.99999") - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "", "", @@ -135,18 +135,18 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "valid - partial claim (interest)", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.LastRedemptionRate = sdk.MustNewDecFromStr("1.049999") zone.RedemptionRate = sdk.MustNewDecFromStr("1.099999") - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "", "", @@ -155,17 +155,17 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "invalid - unbonding not enabled for zone", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.UnbondingEnabled = false - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "unbonding currently disabled for zone testchain2", "unbonding currently disabled for zone testchain2", @@ -174,7 +174,7 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "invalid - wrong denom", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uatom", sdk.NewInt(10000000)), DestinationAddress: addr, @@ -188,7 +188,7 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "invalid - insufficient funds", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(1000000000)), DestinationAddress: addr, @@ -202,7 +202,7 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "invalid - bad prefix", func() { addr, err := bech32.ConvertAndEncode("bob", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.OneInt()), DestinationAddress: addr, @@ -216,7 +216,7 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "invalid - bad from address", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.OneInt()), DestinationAddress: addr, @@ -230,22 +230,22 @@ func (s *KeeperTestSuite) TestRequestRedemption() { "invalid - too many locked tokens", func() { addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), DestinationAddress: addr, FromAddress: testAddress, } - ctx := s.chainA.GetContext() - zoneVals := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetValidatorAddresses(ctx, s.chainB.ChainID) - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetRedelegationRecord(ctx, icstypes.RedelegationRecord{ - ChainId: s.chainB.ChainID, + ctx := suite.chainA.GetContext() + zoneVals := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetValidatorAddresses(ctx, suite.chainB.ChainID) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetRedelegationRecord(ctx, icstypes.RedelegationRecord{ + ChainId: suite.chainB.ChainID, EpochNumber: 1, Source: zoneVals[0], Destination: zoneVals[1], Amount: 3000000, - CompletionTime: s.chainA.GetContext().BlockTime().Add(time.Hour), + CompletionTime: suite.chainA.GetContext().BlockTime().Add(time.Hour), }) }, "", @@ -257,68 +257,68 @@ func (s *KeeperTestSuite) TestRequestRedemption() { tt := tt // run tests with LSM disabled. - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - params := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetParams(ctx) + params := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetParams(ctx) params.UnbondingEnabled = true - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetParams(ctx, params) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetParams(ctx, params) - err := s.GetQuicksilverApp(s.chainA).BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) - s.Require().NoError(err) - err = s.GetQuicksilverApp(s.chainA).BankKeeper.SendCoinsFromModuleToAccount(ctx, icstypes.ModuleName, testAccount, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) - s.Require().NoError(err) + err := suite.GetQuicksilverApp(suite.chainA).BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) + suite.Require().NoError(err) + err = suite.GetQuicksilverApp(suite.chainA).BankKeeper.SendCoinsFromModuleToAccount(ctx, icstypes.ModuleName, testAccount, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) + suite.Require().NoError(err) // disable LSM - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) zone.LiquidityModule = false zone.UnbondingEnabled = true - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(ctx, &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(ctx, &zone) tt.malleate() - msgSrv := icskeeper.NewMsgServerImpl(s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper) - res, err := msgSrv.RequestRedemption(sdk.WrapSDKContext(s.chainA.GetContext()), &msg) + msgSrv := icskeeper.NewMsgServerImpl(suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper) + res, err := msgSrv.RequestRedemption(sdk.WrapSDKContext(suite.chainA.GetContext()), &msg) if tt.expectErr != "" { - s.Require().ErrorContains(err, tt.expectErr) - s.Require().Nil(res) - s.T().Logf("Error: %v", err) + suite.Require().ErrorContains(err, tt.expectErr) + suite.Require().Nil(res) + suite.T().Logf("Error: %v", err) } else { - s.Require().NoError(err) - s.Require().NotNil(res) + suite.Require().NoError(err) + suite.Require().NotNil(res) } }) // run tests with LSM enabled. tt.name += "_LSM_enabled" - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - params := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetParams(ctx) + params := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetParams(ctx) params.UnbondingEnabled = true - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetParams(ctx, params) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetParams(ctx, params) - err := s.GetQuicksilverApp(s.chainA).BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) - s.Require().NoError(err) - err = s.GetQuicksilverApp(s.chainA).BankKeeper.SendCoinsFromModuleToAccount(ctx, icstypes.ModuleName, testAccount, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) - s.Require().NoError(err) + err := suite.GetQuicksilverApp(suite.chainA).BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) + suite.Require().NoError(err) + err = suite.GetQuicksilverApp(suite.chainA).BankKeeper.SendCoinsFromModuleToAccount(ctx, icstypes.ModuleName, testAccount, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) + suite.Require().NoError(err) // enable LSM - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) zone.LiquidityModule = true zone.UnbondingEnabled = true - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(ctx, &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(ctx, &zone) - validators := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetValidatorAddresses(ctx, s.chainB.ChainID) + validators := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetValidatorAddresses(ctx, suite.chainB.ChainID) for _, delegation := range func(zone icstypes.Zone) []icstypes.Delegation { out := make([]icstypes.Delegation, 0) for _, valoper := range validators { @@ -326,43 +326,43 @@ func (s *KeeperTestSuite) TestRequestRedemption() { } return out }(zone) { - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) } tt.malleate() - msgSrv := icskeeper.NewMsgServerImpl(s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper) - res, err := msgSrv.RequestRedemption(sdk.WrapSDKContext(s.chainA.GetContext()), &msg) + msgSrv := icskeeper.NewMsgServerImpl(suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper) + res, err := msgSrv.RequestRedemption(sdk.WrapSDKContext(suite.chainA.GetContext()), &msg) if tt.expectErrLsm != "" { - s.Require().Errorf(err, tt.expectErrLsm) - s.Require().Nil(res) - s.T().Logf("Error: %v", err) + suite.Require().Errorf(err, tt.expectErrLsm) + suite.Require().Nil(res) + suite.T().Logf("Error: %v", err) } else { - s.Require().NoError(err) - s.Require().NotNil(res) + suite.Require().NoError(err) + suite.Require().NotNil(res) } }) } } -func (s *KeeperTestSuite) TestSignalIntent() { +func (suite *KeeperTestSuite) TestSignalIntent() { tests := []struct { name string - malleate func(s *KeeperTestSuite) *icstypes.MsgSignalIntent + malleate func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent expected []sdk.Dec failsValidations bool expectErr bool }{ { "invalid - weight sum < 1", - func(s *KeeperTestSuite) *icstypes.MsgSignalIntent { - val1, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[0].Address.String()) - s.Require().NoError(err) + func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent { + val1, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[0].Address.String()) + suite.Require().NoError(err) return &icstypes.MsgSignalIntent{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Intents: fmt.Sprintf("0.3%s", val1.String()), FromAddress: testAddress, } @@ -373,12 +373,12 @@ func (s *KeeperTestSuite) TestSignalIntent() { }, { "invalid - weight sum > 1", - func(s *KeeperTestSuite) *icstypes.MsgSignalIntent { - val1, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[0].Address.String()) - s.Require().NoError(err) + func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent { + val1, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[0].Address.String()) + suite.Require().NoError(err) return &icstypes.MsgSignalIntent{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Intents: fmt.Sprintf("3.0%s", val1.String()), FromAddress: testAddress, } @@ -389,12 +389,12 @@ func (s *KeeperTestSuite) TestSignalIntent() { }, { "invalid - chain id", - func(s *KeeperTestSuite) *icstypes.MsgSignalIntent { - val1, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[0].Address.String()) - s.Require().NoError(err) + func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent { + val1, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[0].Address.String()) + suite.Require().NoError(err) return &icstypes.MsgSignalIntent{ - ChainId: s.chainA.ChainID, + ChainId: suite.chainA.ChainID, Intents: fmt.Sprintf("1.0%s", val1.String()), FromAddress: testAddress, } @@ -405,12 +405,12 @@ func (s *KeeperTestSuite) TestSignalIntent() { }, { "valid - single weight", - func(s *KeeperTestSuite) *icstypes.MsgSignalIntent { - val1, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[0].Address.String()) - s.Require().NoError(err) + func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent { + val1, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[0].Address.String()) + suite.Require().NoError(err) return &icstypes.MsgSignalIntent{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Intents: fmt.Sprintf("1.0%s", val1.String()), FromAddress: testAddress, } @@ -421,16 +421,16 @@ func (s *KeeperTestSuite) TestSignalIntent() { }, { "valid - multi weight", - func(s *KeeperTestSuite) *icstypes.MsgSignalIntent { - val1, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[0].Address.String()) - s.Require().NoError(err) - val2, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[1].Address.String()) - s.Require().NoError(err) - val3, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[2].Address.String()) - s.Require().NoError(err) + func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent { + val1, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[0].Address.String()) + suite.Require().NoError(err) + val2, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[1].Address.String()) + suite.Require().NoError(err) + val3, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[2].Address.String()) + suite.Require().NoError(err) return &icstypes.MsgSignalIntent{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Intents: fmt.Sprintf("0.5%s,0.2%s,0.3%s", val1.String(), val2.String(), val3.String()), FromAddress: testAddress, } @@ -448,47 +448,47 @@ func (s *KeeperTestSuite) TestSignalIntent() { for _, tt := range tests { tt := tt - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - msg := tt.malleate(s) + msg := tt.malleate(suite) // validateBasic not explicitly tested here - but we don't call it inside msgSrv.SignalIntent // so call here to make sure out tests are sane. err := msg.ValidateBasic() if tt.failsValidations { - s.Require().Error(err) + suite.Require().Error(err) return } - s.Require().NoError(err) + suite.Require().NoError(err) - msgSrv := icskeeper.NewMsgServerImpl(s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper) - res, err := msgSrv.SignalIntent(sdk.WrapSDKContext(s.chainA.GetContext()), msg) + msgSrv := icskeeper.NewMsgServerImpl(suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper) + res, err := msgSrv.SignalIntent(sdk.WrapSDKContext(suite.chainA.GetContext()), msg) if tt.expectErr { - s.Require().Error(err) - s.Require().Nil(res) + suite.Require().Error(err) + suite.Require().Nil(res) } else { - s.Require().NoError(err) - s.Require().NotNil(res) + suite.Require().NoError(err) + suite.Require().NotNil(res) } - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) icsKeeper := quicksilver.InterchainstakingKeeper - zone, found := icsKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) - intent, found := icsKeeper.GetDelegatorIntent(s.chainA.GetContext(), &zone, testAddress, false) - s.Require().True(found) + intent, found := icsKeeper.GetDelegatorIntent(suite.chainA.GetContext(), &zone, testAddress, false) + suite.Require().True(found) intents := intent.GetIntents() for idx, weight := range tt.expected { - val, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[idx].Address.String()) - s.Require().NoError(err) + val, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[idx].Address.String()) + suite.Require().NoError(err) valIntent, found := intents.GetForValoper(val.String()) - s.Require().True(found) + suite.Require().True(found) - s.Require().Equal(weight, valIntent.Weight) + suite.Require().Equal(weight, valIntent.Weight) } }) } diff --git a/x/interchainstaking/keeper/redelegation_record_test.go b/x/interchainstaking/keeper/redelegation_record_test.go index 199e289d4..64aee944e 100644 --- a/x/interchainstaking/keeper/redelegation_record_test.go +++ b/x/interchainstaking/keeper/redelegation_record_test.go @@ -7,17 +7,17 @@ import ( "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -func (s *KeeperTestSuite) TestRedelegationRecordSetGetIterate() { - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestRedelegationRecordSetGetIterate() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() testValidatorOne := utils.GenerateAccAddressForTestWithPrefix("cosmosvaloper") testValidatorTwo := utils.GenerateValAddressForTestWithPrefix("cosmosvaloper") - s.SetupTest() + suite.SetupTest() records := quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx) - s.Require().Equal(0, len(records)) + suite.Require().Equal(0, len(records)) record := types.RedelegationRecord{ ChainId: "cosmoshub-4", @@ -32,22 +32,22 @@ func (s *KeeperTestSuite) TestRedelegationRecordSetGetIterate() { records = quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx) - s.Require().Equal(1, len(records)) + suite.Require().Equal(1, len(records)) recordFetched, found := quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, "cosmoshub-4", testValidatorOne, testValidatorTwo, 1) - s.Require().True(found) - s.Require().Equal(record, recordFetched) + suite.Require().True(found) + suite.Require().Equal(record, recordFetched) allRecords := quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx) - s.Require().Equal(1, len(allRecords)) + suite.Require().Equal(1, len(allRecords)) allCosmosRecords := quicksilver.InterchainstakingKeeper.ZoneRedelegationRecords(ctx, "cosmoshub-4") - s.Require().Equal(1, len(allCosmosRecords)) + suite.Require().Equal(1, len(allCosmosRecords)) allOtherChainRecords := quicksilver.InterchainstakingKeeper.ZoneRedelegationRecords(ctx, "elgafar-1") - s.Require().Equal(0, len(allOtherChainRecords)) + suite.Require().Equal(0, len(allOtherChainRecords)) quicksilver.InterchainstakingKeeper.DeleteRedelegationRecord(ctx, "cosmoshub-4", testValidatorOne, testValidatorTwo, 1) allCosmosRecords = quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx) - s.Require().Equal(0, len(allCosmosRecords)) + suite.Require().Equal(0, len(allCosmosRecords)) } diff --git a/x/interchainstaking/keeper/validator_test.go b/x/interchainstaking/keeper/validator_test.go index c21f0155a..a005a3c28 100644 --- a/x/interchainstaking/keeper/validator_test.go +++ b/x/interchainstaking/keeper/validator_test.go @@ -8,23 +8,23 @@ import ( "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -func (s *KeeperTestSuite) TestStoreGetDeleteValidator() { - s.Run("validator - store / get / delete", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestStoreGetDeleteValidator() { + suite.Run("validator - store / get / delete", func() { + suite.SetupTest() + suite.setupTestZones() - app := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + app := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - zone, found := app.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) validator := utils.GenerateValAddressForTest() valAddrBytes, err := utils.ValAddressFromBech32(validator.String(), zone.GetValoperPrefix()) - s.Require().NoError(err) + suite.Require().NoError(err) _, found = app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) - s.Require().False(found) + suite.Require().False(found) count := len(app.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId)) @@ -40,15 +40,15 @@ func (s *KeeperTestSuite) TestStoreGetDeleteValidator() { count2 := len(app.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId)) - s.Require().Equal(count+1, count2) + suite.Require().Equal(count+1, count2) fetchedValidator, found := app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) - s.Require().True(found) - s.Require().Equal(newValidator, fetchedValidator) + suite.Require().True(found) + suite.Require().Equal(newValidator, fetchedValidator) app.InterchainstakingKeeper.DeleteValidator(ctx, zone.ChainId, valAddrBytes) count3 := len(app.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId)) - s.Require().Equal(count, count3) + suite.Require().Equal(count, count3) }) } From be20f50968d27d6393fa3e83634316c033214a95 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Fri, 2 Jun 2023 16:25:30 +0100 Subject: [PATCH 08/25] remove fmt.Printlns used for debugging --- x/interchainstaking/keeper/delegation_test.go | 3 --- x/interchainstaking/keeper/ibc_packet_handlers.go | 2 -- x/interchainstaking/keeper/ibc_packet_handlers_test.go | 3 --- x/interchainstaking/keeper/receipt.go | 2 -- x/interchainstaking/keeper/redemptions.go | 2 -- 5 files changed, 12 deletions(-) diff --git a/x/interchainstaking/keeper/delegation_test.go b/x/interchainstaking/keeper/delegation_test.go index 0c860af24..c8df21314 100644 --- a/x/interchainstaking/keeper/delegation_test.go +++ b/x/interchainstaking/keeper/delegation_test.go @@ -607,7 +607,6 @@ func (suite *KeeperTestSuite) TestFlushOutstandingDelegations() { test.setStatements(ctx, quicksilver) zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) suite.Require().True(found) - // before := quicksilver.InterchainstakingKeeper.AllReceipts(ctx) err := quicksilver.InterchainstakingKeeper.FlushOutstandingDelegations(ctx, &zone, test.delAddrBalance) // refetch zone after FlushOutstandingDelegations setZone(). ctx = suite.chainA.GetContext() @@ -621,8 +620,6 @@ func (suite *KeeperTestSuite) TestFlushOutstandingDelegations() { suite.Require().NoError(err) } } - // after := quicksilver.InterchainstakingKeeper.AllReceipts(ctx) - // fmt.Println(before, after) suite.Require().NoError(err) isCorrect := test.assertStatements(ctx, quicksilver) suite.Require().True(isCorrect) diff --git a/x/interchainstaking/keeper/ibc_packet_handlers.go b/x/interchainstaking/keeper/ibc_packet_handlers.go index be6ea353f..91c8abdb6 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers.go @@ -854,8 +854,6 @@ func (k *Keeper) HandleDelegate(ctx sdk.Context, msg sdk.Msg, memo string) error } k.Logger(ctx).Debug("outstanding delegations ack-received") k.SetReceiptsCompleted(ctx, zone, time.Unix(exclusionTimestampUnix, 0), ctx.BlockTime()) - fmt.Println(zone.DelegationAddress.Balance) - fmt.Println(delegateMsg.Amount) zone.DelegationAddress.Balance = zone.DelegationAddress.Balance.Sub(delegateMsg.Amount) k.SetZone(ctx, zone) if zone.DelegationAddress.Balance.IsZero() && zone.WithdrawalWaitgroup == 0 { diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index 66352c6c9..01d3c569d 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -423,7 +423,6 @@ func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() { suite.Require().True(found) for _, unbonding := range actualRecord.Distribution { r, found := quicksilver.InterchainstakingKeeper.GetUnbondingRecord(ctx, zone.ChainId, unbonding.Valoper, 1) - fmt.Println(r) suite.Require().True(found) suite.Require().Contains(r.RelatedTxhash, record.Txhash) } @@ -1473,8 +1472,6 @@ func (suite *KeeperTestSuite) TestRebalanceDueToDelegationChange() { // mock ack for redelegations quicksilver.InterchainstakingKeeper.IteratePrefixedRedelegationRecords(ctx, []byte(zone.ChainId), func(idx int64, _ []byte, record icstypes.RedelegationRecord) (stop bool) { - fmt.Println(record) - fmt.Println("##") if record.EpochNumber == 2 { msg := stakingtypes.MsgBeginRedelegate{ DelegatorAddress: zone.DelegationAddress.Address, diff --git a/x/interchainstaking/keeper/receipt.go b/x/interchainstaking/keeper/receipt.go index e178e23c2..3ce0966ee 100644 --- a/x/interchainstaking/keeper/receipt.go +++ b/x/interchainstaking/keeper/receipt.go @@ -62,7 +62,6 @@ func (k Keeper) HandleReceiptTransaction(ctx sdk.Context, txn *tx.Tx, txHash str if senderAddress == Unset { k.Logger(ctx).Error("no sender found. Ignoring.") - fmt.Println("HERE1") k.NilReceipt(ctx, &zone, hash) // nil receipt will stop this hash being submitted again return nil } @@ -302,7 +301,6 @@ func (k *Keeper) SubmitTx(ctx sdk.Context, msgs []sdk.Msg, account *types.ICAAcc func (k Keeper) NilReceipt(ctx sdk.Context, zone *types.Zone, txhash string) { t := ctx.BlockTime() r := types.Receipt{ChainId: zone.ChainId, Sender: "", Txhash: txhash, Amount: sdk.Coins{}, FirstSeen: &t, Completed: &t} - fmt.Println(r) k.SetReceipt(ctx, r) } diff --git a/x/interchainstaking/keeper/redemptions.go b/x/interchainstaking/keeper/redemptions.go index 4302fcc17..60a9aefd1 100644 --- a/x/interchainstaking/keeper/redemptions.go +++ b/x/interchainstaking/keeper/redemptions.go @@ -206,8 +206,6 @@ WITHDRAWAL: allocationsMap[v] = sdk.ZeroInt() if allocationsMap[v].IsZero() { - fmt.Println("valopers len", len(valopers)) - fmt.Println("vidx+1", vidx+1) if len(valopers) > vidx+1 { vidx++ v = valopers[vidx] From b18cd9f29e7b03013e75ce07279918d8b09cdbf5 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Fri, 2 Jun 2023 17:12:30 +0100 Subject: [PATCH 09/25] update participation rewards and protocoldatas, to add validation, automatic key generation, basechain/basedenom in osmosisparams and updated tvl calculation --- app/upgrades/types.go | 1 + app/upgrades/upgrades.go | 31 ++- app/upgrades_test.go | 2 +- x/participationrewards/genesis.go | 2 +- x/participationrewards/genesis_test.go | 2 +- x/participationrewards/keeper/callbacks.go | 4 +- .../keeper/callbacks_test.go | 58 ++-- x/participationrewards/keeper/distribution.go | 55 ++-- .../keeper/distribution_test.go | 4 + x/participationrewards/keeper/grpc_query.go | 2 +- .../keeper/grpc_query_test.go | 32 +-- x/participationrewards/keeper/hooks.go | 2 +- x/participationrewards/keeper/keeper.go | 2 +- x/participationrewards/keeper/keeper_test.go | 252 +++++++++--------- .../keeper/msg_server_test.go | 111 ++++---- .../keeper/proposal_handler.go | 2 +- .../keeper/proposal_handler_test.go | 16 +- .../keeper/protocol_data.go | 14 +- .../keeper/rewards_holdings_test.go | 56 ++-- .../keeper/submodule_liquid.go | 2 +- .../keeper/submodule_osmosis.go | 2 +- x/participationrewards/types/keys.go | 4 +- x/participationrewards/types/proposals.go | 19 +- .../types/proposals_test.go | 7 +- x/participationrewards/types/protocol_data.go | 5 + .../types/submodule_liquid.go | 4 + .../types/submodule_osmosis.go | 33 ++- .../types/submodule_osmosis_test.go | 21 +- 28 files changed, 409 insertions(+), 336 deletions(-) diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 7996c21ed..2e7d40f65 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -24,6 +24,7 @@ const ( V010402rc5UpgradeName = "v1.4.2-rc5" V010402rc6UpgradeName = "v1.4.2-rc6" V010402rc7UpgradeName = "v1.4.2-rc7" + V010403rc0UpgradeName = "v1.4.3-rc0" ) // Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal diff --git a/app/upgrades/upgrades.go b/app/upgrades/upgrades.go index b9c537210..43c03e922 100644 --- a/app/upgrades/upgrades.go +++ b/app/upgrades/upgrades.go @@ -25,6 +25,7 @@ func Upgrades() []Upgrade { {UpgradeName: V010402rc5UpgradeName, CreateUpgradeHandler: V010402rc5UpgradeHandler}, {UpgradeName: V010402rc6UpgradeName, CreateUpgradeHandler: V010402rc6UpgradeHandler}, {UpgradeName: V010402rc7UpgradeName, CreateUpgradeHandler: NoOpHandler}, + {UpgradeName: V010403rc0UpgradeName, CreateUpgradeHandler: V010403rc0UpgradeHandler}, } } @@ -86,7 +87,7 @@ func V010402rc3UpgradeHandler( panic("connection protocol data type not found") } - appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, string(prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), "rege-redwood-1"))) + appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("rege-redwood-1"))) vals := appKeepers.InterchainstakingKeeper.GetValidators(ctx, OsmosisTestnetChainID) for _, val := range vals { valoper, _ := utils.ValAddressFromBech32(val.ValoperAddress, "osmovaloper") @@ -109,8 +110,8 @@ func V010402rc4UpgradeHandler( if !exists { panic("liquid tokens protocol data type not found") } - appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, string(prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), "osmo-test-5/ibc/FBD3AC18A981B89F60F9FE5B21BD7F1DE87A53C3505D5A5E438E2399409CFB6F"))) - appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, string(prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), "rhye-1/uqosmo"))) + appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("osmo-test-5/ibc/FBD3AC18A981B89F60F9FE5B21BD7F1DE87A53C3505D5A5E438E2399409CFB6F"))) + appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("rhye-1/uqosmo"))) rcptTime := time.Unix(1682932342, 0) rcpt1 := types.Receipt{ ChainId: "theta-testnet-001", @@ -250,6 +251,30 @@ func V010402rc6UpgradeHandler( } } +func V010403rc0UpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + appKeepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + if isTestnet(ctx) || isTest(ctx) { + appKeepers.ParticipationRewardsKeeper.IteratePrefixedProtocolDatas(ctx, prtypes.GetPrefixProtocolDataKey(prtypes.ProtocolDataTypeLiquidToken), func(index int64, key []byte, data prtypes.ProtocolData) (stop bool) { + prefixedKey := append(prtypes.GetPrefixProtocolDataKey(prtypes.ProtocolDataTypeLiquidToken), key...) + appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prefixedKey) + pd, err := prtypes.UnmarshalProtocolData(prtypes.ProtocolDataTypeLiquidToken, data.Data) + if err != nil { + panic(err) + } + newKey := pd.GenerateKey() + appKeepers.ParticipationRewardsKeeper.SetProtocolData(ctx, newKey, &data) + return false + }) + } + + return mm.RunMigrations(ctx, configurator, fromVM) + } +} + // func V010400UpgradeHandler( // mm *module.Manager, // configurator module.Configurator, diff --git a/app/upgrades_test.go b/app/upgrades_test.go index b0ecaceb3..59e9b2d86 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -316,7 +316,7 @@ func (s *AppTestSuite) TestV010402rc3UpgradeHandler() { Data: []byte(`{"ConnectionID":"connection-2","ChainID":"regen-redwood-1","Prefix":"regen"}`), } - app.ParticipationRewardsKeeper.SetProtocolData(ctx, string(prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), "rege-redwood-1")), &prData) + app.ParticipationRewardsKeeper.SetProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("rege-redwood-1")), &prData) val0 := icstypes.Validator{ValoperAddress: "osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc", CommissionRate: sdk.MustNewDecFromStr("1"), VotingPower: sdk.NewInt(2000), Status: stakingtypes.BondStatusBonded} app.InterchainstakingKeeper.SetValidator(ctx, upgrades.OsmosisTestnetChainID, val0) val1 := icstypes.Validator{ValoperAddress: "osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk", CommissionRate: sdk.MustNewDecFromStr("1"), VotingPower: sdk.NewInt(2000), Status: stakingtypes.BondStatusBonded} diff --git a/x/participationrewards/genesis.go b/x/participationrewards/genesis.go index 72c13b768..988723bf1 100644 --- a/x/participationrewards/genesis.go +++ b/x/participationrewards/genesis.go @@ -13,7 +13,7 @@ func InitGenesis(ctx sdk.Context, k *keeper.Keeper, genState types.GenesisState) k.SetParams(ctx, genState.Params) for _, kpd := range genState.ProtocolData { - k.SetProtocolData(ctx, kpd.Key, kpd.ProtocolData) + k.SetProtocolData(ctx, []byte(kpd.Key), kpd.ProtocolData) } } diff --git a/x/participationrewards/genesis_test.go b/x/participationrewards/genesis_test.go index 54230b993..b40a3649f 100644 --- a/x/participationrewards/genesis_test.go +++ b/x/participationrewards/genesis_test.go @@ -33,7 +33,7 @@ func TestParticipationRewardsExportGenesis(t *testing.T) { } protocolData := types.NewProtocolData(types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisPool)], bz) - app.ParticipationRewardsKeeper.SetProtocolData(ctx, fmt.Sprintf("%d", pool.PoolID), protocolData) + app.ParticipationRewardsKeeper.SetProtocolData(ctx, []byte(fmt.Sprintf("%d", pool.PoolID)), protocolData) genesis := participationrewards.ExportGenesis(ctx, app.ParticipationRewardsKeeper) diff --git a/x/participationrewards/keeper/callbacks.go b/x/participationrewards/keeper/callbacks.go index 0b025be64..6f7a07efa 100644 --- a/x/participationrewards/keeper/callbacks.go +++ b/x/participationrewards/keeper/callbacks.go @@ -134,7 +134,7 @@ func OsmosisPoolUpdateCallback(ctx sdk.Context, k *Keeper, response []byte, quer if err != nil { return err } - k.SetProtocolData(ctx, fmt.Sprintf("%d", poolID), &data) + k.SetProtocolData(ctx, pool.GenerateKey(), &data) return nil } @@ -193,6 +193,6 @@ func SetEpochBlockCallback(ctx sdk.Context, k *Keeper, args []byte, query icqtyp if err != nil { return err } - k.SetProtocolData(ctx, query.ChainId, &data) + k.SetProtocolData(ctx, connectionData.GenerateKey(), &data) return nil } diff --git a/x/participationrewards/keeper/callbacks_test.go b/x/participationrewards/keeper/callbacks_test.go index 87c1d1dc3..95577c23e 100644 --- a/x/participationrewards/keeper/callbacks_test.go +++ b/x/participationrewards/keeper/callbacks_test.go @@ -15,15 +15,15 @@ import ( "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -func (s *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { - prk := s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { + prk := suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper + ctx := suite.chainA.GetContext() osm := &keeper.OsmosisModule{} qid := icqkeeper.GenerateQueryHash("connection-77002", "osmosis-1", "store/gamm/key", osm.GetKeyPrefixPools(1), types.ModuleName) query, found := prk.IcqKeeper.GetQuery(ctx, qid) - s.Require().True(found, "qid: %s", qid) + suite.Require().True(found, "qid: %s", qid) var err error resp := []byte{10, 26, 47, 111, 115, 109, 111, 115, 105, 115, 46, 103, 97, 109, 109, 46, 118, 49, 98, 101, 116, 97, 49, 46, 80, 111, 111, 108, 18, 202, 2, 10, 63, 111, 115, 109, 111, 49, 109, 119, 48, 97, 99, 54, 114, 119, 108, 112, 53, 114, 56, 119, 97, 112, 119, 107, 51, 122, 115, 54, 103, 50, 57, 104, 56, 102, 99, 115, 99, 120, 113, 97, 107, 100, 122, 119, 57, 101, 109, 107, 110, 101, 54, 99, 56, 119, 106, 112, 57, 113, 48, 116, 51, 118, 56, 116, 16, 1, 26, 6, 10, 1, 48, 18, 1, 48, 34, 4, 49, 54, 56, 104, 42, 43, 10, 11, 103, 97, 109, 109, 47, 112, 111, 111, 108, 47, 49, 18, 28, 49, 48, 48, 48, 48, 48, 48, 50, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 48, 48, 50, 94, 10, 80, 10, 68, 105, 98, 99, 47, 49, 53, 69, 57, 67, 53, 67, 70, 53, 57, 54, 57, 48, 56, 48, 53, 51, 57, 68, 66, 51, 57, 53, 70, 65, 55, 68, 57, 67, 48, 56, 54, 56, 50, 54, 53, 50, 49, 55, 69, 70, 67, 53, 50, 56, 52, 51, 51, 54, 55, 49, 65, 65, 70, 57, 66, 49, 57, 49, 50, 68, 49, 53, 57, 18, 8, 49, 48, 48, 48, 48, 48, 48, 51, 18, 10, 49, 48, 55, 51, 55, 52, 49, 56, 50, 52, 50, 94, 10, 80, 10, 68, 105, 98, 99, 47, 51, 48, 50, 48, 57, 50, 50, 66, 55, 53, 55, 54, 70, 67, 55, 53, 66, 66, 69, 48, 53, 55, 65, 48, 50, 57, 48, 65, 57, 65, 69, 69, 70, 70, 52, 56, 57, 66, 66, 49, 49, 49, 51, 69, 54, 69, 51, 54, 53, 67, 69, 52, 55, 50, 68, 52, 66, 70, 66, 55, 70, 70, 65, 51, 18, 8, 49, 48, 48, 48, 48, 48, 48, 51, 18, 10, 49, 48, 55, 51, 55, 52, 49, 56, 50, 52, 58, 10, 50, 49, 52, 55, 52, 56, 51, 54, 52, 56} @@ -34,9 +34,9 @@ func (s *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { // setup for expected var pdi gamm.PoolI err = prk.GetCodec().UnmarshalInterface(resp, &pdi) - s.Require().NoError(err) + suite.Require().NoError(err) expectedData, err := json.Marshal(pdi) - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.OsmosisPoolUpdateCallback( ctx, @@ -44,7 +44,7 @@ func (s *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { resp, query, ) - s.Require().NoError(err) + suite.Require().NoError(err) want := &types.OsmosisPoolProtocolData{ PoolID: 1, @@ -59,31 +59,31 @@ func (s *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { } pd, found := prk.GetProtocolData(ctx, types.ProtocolDataTypeOsmosisPool, "1") - s.Require().True(found) + suite.Require().True(found) ioppd, err := types.UnmarshalProtocolData(types.ProtocolDataTypeOsmosisPool, pd.Data) - s.Require().NoError(err) + suite.Require().NoError(err) oppd := ioppd.(*types.OsmosisPoolProtocolData) - s.Require().Equal(want, oppd) + suite.Require().Equal(want, oppd) } -func (s *KeeperTestSuite) executeValidatorSelectionRewardsCallback(performanceAddress string, valRewards map[string]sdk.Dec) { - prk := s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) executeValidatorSelectionRewardsCallback(performanceAddress string, valRewards map[string]sdk.Dec) { + prk := suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper + ctx := suite.chainA.GetContext() rewardsQuery := distrtypes.QueryDelegationTotalRewardsRequest{DelegatorAddress: performanceAddress} bz := prk.GetCodec().MustMarshal(&rewardsQuery) qid := icqkeeper.GenerateQueryHash( - s.path.EndpointA.ConnectionID, - s.chainB.ChainID, + suite.path.EndpointA.ConnectionID, + suite.chainB.ChainID, "cosmos.distribution.v1beta1.Query/DelegationTotalRewards", bz, types.ModuleName, ) query, found := prk.IcqKeeper.GetQuery(ctx, qid) - s.Require().True(found, "qid: %s", qid) + suite.Require().True(found, "qid: %s", qid) var respJSON strings.Builder respJSON.Write([]byte(`{"rewards":[`)) @@ -100,9 +100,9 @@ func (s *KeeperTestSuite) executeValidatorSelectionRewardsCallback(performanceAd respJSON.Write([]byte(fmt.Sprintf(`],"total":[{"denom":"uatom","amount":%q}]}`, total.String()))) qdtrResp := distrtypes.QueryDelegationTotalRewardsResponse{} err := json.Unmarshal([]byte(respJSON.String()), &qdtrResp) - s.Require().NoError(err) + suite.Require().NoError(err) resp, err := qdtrResp.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.ValidatorSelectionRewardsCallback( ctx, @@ -110,32 +110,32 @@ func (s *KeeperTestSuite) executeValidatorSelectionRewardsCallback(performanceAd resp, query, ) - s.Require().NoError(err) + suite.Require().NoError(err) } -func (s *KeeperTestSuite) executeSetEpochBlockCallback() { - prk := s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) executeSetEpochBlockCallback() { + prk := suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper + ctx := suite.chainA.GetContext() blockQuery := tmservice.GetLatestBlockRequest{} bz := prk.GetCodec().MustMarshal(&blockQuery) qid := icqkeeper.GenerateQueryHash( - s.path.EndpointA.ConnectionID, - s.chainB.ChainID, + suite.path.EndpointA.ConnectionID, + suite.chainB.ChainID, "cosmos.base.tendermint.v1beta1.Service/GetLatestBlock", bz, types.ModuleName, ) query, found := prk.IcqKeeper.GetQuery(ctx, qid) - s.Require().True(found, "qid: %s", qid) + suite.Require().True(found, "qid: %s", qid) respJSON := `{"block_id":{"hash":"74pkkjg7u1eLtXxFCinnCmln3aVZVOqLCT3OnE3D+VA=","part_set_header":{"total":1,"hash":"UiLM70PpplmmZ85qC0ZKva5kYJmSZ2TTEZ4a7g9G92Q="}},"block":{"header":{"version":{"block":"11","app":"0"},"chain_id":"quickgaia-1","height":"90767","time":"2022-11-03T09:12:23.109926769Z","last_block_id":{"hash":"wCK5QmPuGJiRpn06Xu7ZjhxHwzBXVZrGqngMMzeRq8w=","part_set_header":{"total":1,"hash":"xYxXM7rX6Qcq/Yx3MpZeQA+FCeUbKSVr/FEuzfAFFQk="}},"last_commit_hash":"1Ev2iL1pTgyItBtSFbCRzxwdCtJfaCC1P+zWaDkJ/nU=","data_hash":"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=","validators_hash":"kQ9NNQ26Q3l5aXF2IwraaweoLzusIVDUA53AycOe1PI=","next_validators_hash":"kQ9NNQ26Q3l5aXF2IwraaweoLzusIVDUA53AycOe1PI=","consensus_hash":"BICRvH3cKD93v7+R1zxE2ljD34qcvIZ0Bdi389qtoi8=","app_hash":"j3x5PuEH14QVBqWUv6BhKitzXMTJ2w47h2Nj99JKtlI=","last_results_hash":"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=","evidence_hash":"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=","proposer_address":"YVEp2+U79qlwIpwaKr4rObvWbHo="},"data":{"txs":[]},"evidence":{"evidence":[]},"last_commit":{"height":"90766","round":0,"block_id":{"hash":"wCK5QmPuGJiRpn06Xu7ZjhxHwzBXVZrGqngMMzeRq8w=","part_set_header":{"total":1,"hash":"xYxXM7rX6Qcq/Yx3MpZeQA+FCeUbKSVr/FEuzfAFFQk="}},"signatures":[{"block_id_flag":"BLOCK_ID_FLAG_COMMIT","validator_address":"WRBCW5t/kdjOaTvYz9TaySfc8xU=","timestamp":"2022-11-03T09:12:23.109926769Z","signature":"LAbAFCM2MlT1QeNnhZoD8xPe6fO6GExtDNdwa8sokr9UZjurHWn3ad9U2BhTLFVKUF6j7r9G9ILKshljKn4/Aw=="},{"block_id_flag":"BLOCK_ID_FLAG_COMMIT","validator_address":"YVEp2+U79qlwIpwaKr4rObvWbHo=","timestamp":"2022-11-03T09:12:23.104507119Z","signature":"KxHLYnn97GG9prtLA+qurq5GvZogcoExpCvWmOOd8uS3m1Tug5qptSxZ2AObiUfyDwl23oqNNEhkp2XxsxcOCA=="},{"block_id_flag":"BLOCK_ID_FLAG_COMMIT","validator_address":"agVlYuY3F6RGyBUe5zgd0oFhoCM=","timestamp":"2022-11-03T09:12:23.109928409Z","signature":"vvL6yIdxyT4Eus/xw8/RWvFymUFNiOsJ+hHM/qwSJQt427hdUiIh/iH6+yZGz5bdpChW4/Y4bB1QnIA8q1SjBw=="}]}}}` glbrResp := tmservice.GetLatestBlockResponse{} - err := s.GetQuicksilverApp(s.chainA).AppCodec().UnmarshalJSON([]byte(respJSON), &glbrResp) - s.Require().NoError(err) + err := suite.GetQuicksilverApp(suite.chainA).AppCodec().UnmarshalJSON([]byte(respJSON), &glbrResp) + suite.Require().NoError(err) resp, err := glbrResp.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.SetEpochBlockCallback( ctx, @@ -143,5 +143,5 @@ func (s *KeeperTestSuite) executeSetEpochBlockCallback() { resp, query, ) - s.Require().NoError(err) + suite.Require().NoError(err) } diff --git a/x/participationrewards/keeper/distribution.go b/x/participationrewards/keeper/distribution.go index 4d335437e..e2e94bdf0 100644 --- a/x/participationrewards/keeper/distribution.go +++ b/x/participationrewards/keeper/distribution.go @@ -8,7 +8,6 @@ import ( "github.com/ingenuity-build/quicksilver/internal/multierror" "github.com/ingenuity-build/quicksilver/utils" - icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) @@ -17,28 +16,26 @@ type tokenValues map[string]sdk.Dec func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { k.Logger(ctx).Info("calcTokenValues") - tvs := make(map[string]sdk.Dec) - - // get base zone (Cosmos) - var cosmosZone *icstypes.Zone - k.icsKeeper.IterateZones(ctx, func(_ int64, zone *icstypes.Zone) (stop bool) { - if zone.AccountPrefix == "cosmos" { - cosmosZone = zone - return true - } - return false - }) - if cosmosZone == nil { - return nil, errors.New("unable to find Cosmos zone") + data, found := k.GetProtocolData(ctx, types.ProtocolDataTypeOsmosisParams, "osmosisparams") + if !found { + return tokenValues{}, errors.New("could not find osmosisparams protocol data") + } + osmoParams, err := types.UnmarshalProtocolData(types.ProtocolDataTypeOsmosisParams, data.Data) + if err != nil { + return tokenValues{}, err } + baseDenom := osmoParams.(*types.OsmosisParamsProtocolData).BaseDenom + baseChain := osmoParams.(*types.OsmosisParamsProtocolData).BaseChain + + tvs := make(map[string]sdk.Dec) + // add base value - tvs[cosmosZone.BaseDenom] = sdk.OneDec() - // tvs[uatom] = 1.0 + tvs[baseDenom] = sdk.OneDec() - // capture errors from iterator + // capture errors from iteratora errs := make(map[string]error) - k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeOsmosisPool), func(idx int64, data types.ProtocolData) bool { + k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeOsmosisPool), func(idx int64, _ []byte, data types.ProtocolData) bool { idxLabel := fmt.Sprintf("index[%d]", idx) ipool, err := types.UnmarshalProtocolData(types.ProtocolDataTypeOsmosisPool, data.Data) if err != nil { @@ -58,26 +55,26 @@ func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { // - queryIBCDenom -> the target IBC denom in this pair // - valueDenom -> the target zone.BaseDenom var baseIBCDenom, queryIBCDenom, valueDenom string - isCosmosPair := false + isBasePair := false for chainID, denom := range pool.Zones { + if chainID == baseChain { + isBasePair = true + baseIBCDenom = denom + continue + } + zone, ok := k.icsKeeper.GetZone(ctx, chainID) if !ok { errs[idxLabel] = fmt.Errorf("zone not found, %s", chainID) return true } - if zone.AccountPrefix == "cosmos" { - isCosmosPair = true - baseIBCDenom = denom - continue - } - queryIBCDenom = denom valueDenom = zone.BaseDenom } - if isCosmosPair { + if isBasePair { if pool.PoolData == nil { errs[idxLabel] = fmt.Errorf("pool data is nil, awaiting OsmosisPoolUpdateCallback") return true @@ -112,7 +109,7 @@ func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { func (k *Keeper) AllocateZoneRewards(ctx sdk.Context, tvs tokenValues, allocation types.RewardsAllocation) error { k.Logger(ctx).Info("allocateZoneRewards", "token values", tvs, "allocation", allocation) - if err := k.setZoneAllocations(ctx, tvs, allocation); err != nil { + if err := k.SetZoneAllocations(ctx, tvs, allocation); err != nil { return err } @@ -121,9 +118,9 @@ func (k *Keeper) AllocateZoneRewards(ctx sdk.Context, tvs tokenValues, allocatio return k.AllocateHoldingsRewards(ctx) } -// setZoneAllocations returns the proportional zone rewards allocations as a +// SetZoneAllocations returns the proportional zone rewards allocations as a // map indexed by the zone id. -func (k *Keeper) setZoneAllocations(ctx sdk.Context, tvs tokenValues, allocation types.RewardsAllocation) error { +func (k *Keeper) SetZoneAllocations(ctx sdk.Context, tvs tokenValues, allocation types.RewardsAllocation) error { k.Logger(ctx).Info("setZoneAllocations", "allocation", allocation) otvl := sdk.ZeroDec() diff --git a/x/participationrewards/keeper/distribution_test.go b/x/participationrewards/keeper/distribution_test.go index 942926490..d666193bc 100644 --- a/x/participationrewards/keeper/distribution_test.go +++ b/x/participationrewards/keeper/distribution_test.go @@ -1 +1,5 @@ package keeper_test + +func (suite *KeeperTestSuite) SetZoneAllocationsTest() { + +} diff --git a/x/participationrewards/keeper/grpc_query.go b/x/participationrewards/keeper/grpc_query.go index 42c7db418..b4fb86348 100644 --- a/x/participationrewards/keeper/grpc_query.go +++ b/x/participationrewards/keeper/grpc_query.go @@ -29,7 +29,7 @@ func (k *Keeper) ProtocolData(c context.Context, q *types.QueryProtocolDataReque } prefix := append(types.GetPrefixProtocolDataKey(types.ProtocolDataType(pdType)), []byte(q.Key)...) - k.IteratePrefixedProtocolDatas(ctx, prefix, func(index int64, data types.ProtocolData) (stop bool) { + k.IteratePrefixedProtocolDatas(ctx, prefix, func(index int64, _ []byte, data types.ProtocolData) (stop bool) { out = append(out, data.Data) return false }) diff --git a/x/participationrewards/keeper/grpc_query_test.go b/x/participationrewards/keeper/grpc_query_test.go index f2312b7a4..a0a81a8f6 100644 --- a/x/participationrewards/keeper/grpc_query_test.go +++ b/x/participationrewards/keeper/grpc_query_test.go @@ -7,37 +7,37 @@ import ( "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -func (s *KeeperTestSuite) TestKeeper_Params() { - s.Run("Params", func() { - k := s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper +func (suite *KeeperTestSuite) TestKeeper_Params() { + suite.Run("Params", func() { + k := suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper want := types.QueryParamsResponse{ Params: types.DefaultParams(), } - got, err := k.Params(s.chainA.GetContext(), &types.QueryParamsRequest{}) - s.Require().NoError(err) - s.Require().NotNil(got) - s.Require().Equal(want, *got) + got, err := k.Params(suite.chainA.GetContext(), &types.QueryParamsRequest{}) + suite.Require().NoError(err) + suite.Require().NotNil(got) + suite.Require().Equal(want, *got) }) } -func (s *KeeperTestSuite) TestKeeper_ProtocolData() { - connpdstr := fmt.Sprintf("{\"ConnectionID\":%q,\"ChainID\":%q,\"LastEpoch\":%d,\"Prefix\":\"\"}", s.path.EndpointB.ConnectionID, s.chainB.ChainID, 90767) - s.Run("ProtocolData", func() { - k := s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper +func (suite *KeeperTestSuite) TestKeeper_ProtocolData() { + connpdstr := fmt.Sprintf("{\"ConnectionID\":%q,\"ChainID\":%q,\"LastEpoch\":%d,\"Prefix\":\"\"}", suite.path.EndpointB.ConnectionID, suite.chainB.ChainID, 90767) + suite.Run("ProtocolData", func() { + k := suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper want := types.QueryProtocolDataResponse{ Data: []encoding_json.RawMessage{ []byte(connpdstr), }, } got, err := k.ProtocolData( - s.chainA.GetContext(), + suite.chainA.GetContext(), &types.QueryProtocolDataRequest{ Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeConnection)], - Key: s.chainB.ChainID, + Key: suite.chainB.ChainID, }, ) - s.Require().NoError(err) - s.Require().NotNil(got) - s.Require().Equal(want, *got) + suite.Require().NoError(err) + suite.Require().NotNil(got) + suite.Require().Equal(want, *got) }) } diff --git a/x/participationrewards/keeper/hooks.go b/x/participationrewards/keeper/hooks.go index 807fa3307..200e496c4 100644 --- a/x/participationrewards/keeper/hooks.go +++ b/x/participationrewards/keeper/hooks.go @@ -14,7 +14,7 @@ func (k *Keeper) BeforeEpochStart(_ sdk.Context, _ string, _ int64) error { func (k *Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, _ int64) error { if epochIdentifier == epochstypes.EpochIdentifierEpoch { - k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeConnection), func(index int64, data types.ProtocolData) (stop bool) { + k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeConnection), func(index int64, _ []byte, data types.ProtocolData) (stop bool) { blockQuery := tmservice.GetLatestBlockRequest{} bz := k.cdc.MustMarshal(&blockQuery) diff --git a/x/participationrewards/keeper/keeper.go b/x/participationrewards/keeper/keeper.go index 301770599..e8f32446a 100644 --- a/x/participationrewards/keeper/keeper.go +++ b/x/participationrewards/keeper/keeper.go @@ -134,7 +134,7 @@ func (k *Keeper) UpdateSelfConnectionData(ctx sdk.Context) error { Data: selfConnectionData, } k.Logger(ctx).Info("Setting self protocol data", "data", data) - k.SetProtocolData(ctx, ctx.ChainID(), &data) + k.SetProtocolData(ctx, []byte(ctx.ChainID()), &data) return nil } diff --git a/x/participationrewards/keeper/keeper_test.go b/x/participationrewards/keeper/keeper_test.go index 1b4dc953d..30eb597ac 100644 --- a/x/participationrewards/keeper/keeper_test.go +++ b/x/participationrewards/keeper/keeper_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/stretchr/testify/suite" + testsuite "github.com/stretchr/testify/suite" "cosmossdk.io/math" @@ -35,7 +35,7 @@ func init() { // TestKeeperTestSuite runs all the tests within this package. func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(KeeperTestSuite)) + testsuite.Run(t, new(KeeperTestSuite)) } func newQuicksilverPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { @@ -47,7 +47,7 @@ func newQuicksilverPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { } type KeeperTestSuite struct { - suite.Suite + testsuite.Suite coordinator *ibctesting.Coordinator @@ -58,7 +58,7 @@ type KeeperTestSuite struct { path *ibctesting.Path } -func (s *KeeperTestSuite) GetQuicksilverApp(chain *ibctesting.TestChain) *app.Quicksilver { +func (suite *KeeperTestSuite) GetQuicksilverApp(chain *ibctesting.TestChain) *app.Quicksilver { quicksilver, ok := chain.App.(*app.Quicksilver) if !ok { panic("not quicksilver app") @@ -68,85 +68,85 @@ func (s *KeeperTestSuite) GetQuicksilverApp(chain *ibctesting.TestChain) *app.Qu } // SetupTest creates a coordinator with 2 test chains. -func (s *KeeperTestSuite) SetupTest() { - s.coordinator = ibctesting.NewCoordinator(s.T(), 2) // initializes 2 test chains - s.chainA = s.coordinator.GetChain(ibctesting.GetChainID(1)) // convenience and readability - s.chainB = s.coordinator.GetChain(ibctesting.GetChainID(2)) // convenience and readability +func (suite *KeeperTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) // initializes 2 test chains + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) // convenience and readability + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) // convenience and readability - s.path = newQuicksilverPath(s.chainA, s.chainB) - s.coordinator.SetupConnections(s.path) + suite.path = newQuicksilverPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(suite.path) - s.coordinator.CurrentTime = time.Now().UTC() - s.coordinator.UpdateTime() + suite.coordinator.CurrentTime = time.Now().UTC() + suite.coordinator.UpdateTime() - s.coreTest() + suite.coreTest() } -func (s *KeeperTestSuite) coreTest() { - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) coreTest() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) - s.setupTestZones() + suite.setupTestZones() // test ProtocolData - akpd := quicksilver.ParticipationRewardsKeeper.AllKeyedProtocolDatas(s.chainA.GetContext()) + akpd := quicksilver.ParticipationRewardsKeeper.AllKeyedProtocolDatas(suite.chainA.GetContext()) // initially we expect one - the 'local' chain - s.Require().Equal(1, len(akpd)) + suite.Require().Equal(1, len(akpd)) - s.setupTestProtocolData() + suite.setupTestProtocolData() - akpd = quicksilver.ParticipationRewardsKeeper.AllKeyedProtocolDatas(s.chainA.GetContext()) + akpd = quicksilver.ParticipationRewardsKeeper.AllKeyedProtocolDatas(suite.chainA.GetContext()) // added 6 in setupTestProtocolData - s.Require().Equal(7, len(akpd)) + suite.Require().Equal(7, len(akpd)) // advance the chains - s.coordinator.CommitNBlocks(s.chainA, 1) - s.coordinator.CommitNBlocks(s.chainB, 1) + suite.coordinator.CommitNBlocks(suite.chainA, 1) + suite.coordinator.CommitNBlocks(suite.chainB, 1) // callback test - s.executeSetEpochBlockCallback() - s.executeOsmosisPoolUpdateCallback() + suite.executeSetEpochBlockCallback() + suite.executeOsmosisPoolUpdateCallback() - s.setupTestDeposits() - s.setupTestIntents() + suite.setupTestDeposits() + suite.setupTestIntents() - quicksilver.EpochsKeeper.AfterEpochEnd(s.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 1) + quicksilver.EpochsKeeper.AfterEpochEnd(suite.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 1) - s.setupTestClaims() + suite.setupTestClaims() - quicksilver.EpochsKeeper.AfterEpochEnd(s.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 2) + quicksilver.EpochsKeeper.AfterEpochEnd(suite.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 2) // Epoch boundary - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() quicksilver.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { - s.Require().NoError(quicksilver.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(quicksilver.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) - s.Require().NoError(quicksilver.BankKeeper.SendCoinsFromModuleToModule(ctx, "mint", types.ModuleName, sdk.NewCoins(sdk.NewCoin(quicksilver.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) + suite.Require().NoError(quicksilver.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(quicksilver.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) + suite.Require().NoError(quicksilver.BankKeeper.SendCoinsFromModuleToModule(ctx, "mint", types.ModuleName, sdk.NewCoins(sdk.NewCoin(quicksilver.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) return false }) _, found := quicksilver.ClaimsManagerKeeper.GetLastEpochClaim(ctx, "cosmoshub-4", "quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure", cmtypes.ClaimTypeLiquidToken, "osmosis-1") - s.Require().True(found) + suite.Require().True(found) - quicksilver.EpochsKeeper.AfterEpochEnd(s.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 3) + quicksilver.EpochsKeeper.AfterEpochEnd(suite.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 3) // zone for remote chain - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) valRewards := make(map[string]sdk.Dec) - for _, val := range quicksilver.InterchainstakingKeeper.GetValidators(s.chainA.GetContext(), s.chainB.ChainID) { + for _, val := range quicksilver.InterchainstakingKeeper.GetValidators(suite.chainA.GetContext(), suite.chainB.ChainID) { valRewards[val.ValoperAddress] = sdk.NewDec(100000000) } - s.executeValidatorSelectionRewardsCallback(zone.PerformanceAddress.Address, valRewards) + suite.executeValidatorSelectionRewardsCallback(zone.PerformanceAddress.Address, valRewards) } -func (s *KeeperTestSuite) setupTestZones() { - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) setupTestZones() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) // test zone testzone := icstypes.Zone{ - ConnectionId: s.path.EndpointA.ConnectionID, - ChainId: s.chainB.ChainID, + ConnectionId: suite.path.EndpointA.ConnectionID, + ChainId: suite.chainB.ChainID, AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom", @@ -157,8 +157,8 @@ func (s *KeeperTestSuite) setupTestZones() { Is_118: true, } selftestzone := icstypes.Zone{ - ConnectionId: s.path.EndpointB.ConnectionID, - ChainId: s.chainA.ChainID, + ConnectionId: suite.path.EndpointB.ConnectionID, + ChainId: suite.chainA.ChainID, AccountPrefix: "osmo", LocalDenom: "uqosmo", BaseDenom: "uosmo", @@ -169,26 +169,26 @@ func (s *KeeperTestSuite) setupTestZones() { Is_118: true, } - quicksilver.InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &selftestzone) - quicksilver.InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &testzone) + quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &selftestzone) + quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &testzone) - quicksilver.IBCKeeper.ClientKeeper.SetClientState(s.chainA.GetContext(), "07-tendermint-0", &tmclienttypes.ClientState{ChainId: s.chainB.ChainID, TrustingPeriod: time.Hour, LatestHeight: clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}}) + quicksilver.IBCKeeper.ClientKeeper.SetClientState(suite.chainA.GetContext(), "07-tendermint-0", &tmclienttypes.ClientState{ChainId: suite.chainB.ChainID, TrustingPeriod: time.Hour, LatestHeight: clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}}) - quicksilver.IBCKeeper.ClientKeeper.SetClientConsensusState(s.chainA.GetContext(), "07-tendermint-0", clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}, &tmclienttypes.ConsensusState{Timestamp: s.chainA.GetContext().BlockTime()}) - s.Require().NoError(s.setupChannelForICA(s.chainB.ChainID, s.path.EndpointA.ConnectionID, "performance", testzone.AccountPrefix)) + quicksilver.IBCKeeper.ClientKeeper.SetClientConsensusState(suite.chainA.GetContext(), "07-tendermint-0", clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}, &tmclienttypes.ConsensusState{Timestamp: suite.chainA.GetContext().BlockTime()}) + suite.Require().NoError(suite.setupChannelForICA(suite.chainB.ChainID, suite.path.EndpointA.ConnectionID, "performance", testzone.AccountPrefix)) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetBondedValidatorsByPower(s.chainB.GetContext()) - zone, found := quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetBondedValidatorsByPower(suite.chainB.GetContext()) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) for i := range vals { - s.Require().NoError(quicksilver.InterchainstakingKeeper.SetValidatorForZone(s.chainA.GetContext(), &zone, app.DefaultConfig().Codec.MustMarshal(&vals[i]))) + suite.Require().NoError(quicksilver.InterchainstakingKeeper.SetValidatorForZone(suite.chainA.GetContext(), &zone, app.DefaultConfig().Codec.MustMarshal(&vals[i]))) } // self zone performanceAddressOsmo := utils.GenerateAccAddressForTestWithPrefix("osmo") performanceAccountOsmo, err := icstypes.NewICAAccount(performanceAddressOsmo, "self") - s.Require().NoError(err) + suite.Require().NoError(err) performanceAccountOsmo.WithdrawalAddress = utils.GenerateAccAddressForTestWithPrefix("osmo") zoneSelf := icstypes.Zone{ @@ -228,12 +228,12 @@ func (s *KeeperTestSuite) setupTestZones() { }, }, } - quicksilver.InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zoneSelf) + quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zoneSelf) // cosmos zone performanceAddressCosmos := utils.GenerateAccAddressForTestWithPrefix("cosmos") performanceAccountCosmos, err := icstypes.NewICAAccount(performanceAddressCosmos, "cosmoshub-4.performance") - s.Require().NoError(err) + suite.Require().NoError(err) performanceAccountCosmos.WithdrawalAddress = utils.GenerateAccAddressForTestWithPrefix("cosmos") zoneCosmos := icstypes.Zone{ @@ -247,7 +247,7 @@ func (s *KeeperTestSuite) setupTestZones() { PerformanceAddress: performanceAccountCosmos, Is_118: true, } - quicksilver.InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zoneCosmos) + quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zoneCosmos) cosmosVals := []icstypes.Validator{ { ValoperAddress: "cosmosvaloper1759teakrsvnx7rnur8ezc4qaq8669nhtgukm0x", @@ -272,7 +272,7 @@ func (s *KeeperTestSuite) setupTestZones() { }, } for _, cosmosVal := range cosmosVals { - quicksilver.InterchainstakingKeeper.SetValidator(s.chainA.GetContext(), zoneCosmos.ChainId, cosmosVal) + quicksilver.InterchainstakingKeeper.SetValidator(suite.chainA.GetContext(), zoneCosmos.ChainId, cosmosVal) } // osmosis zone @@ -291,12 +291,12 @@ func (s *KeeperTestSuite) setupTestZones() { }, Is_118: true, } - quicksilver.InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zoneOsmosis) + quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zoneOsmosis) } -func (s *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountSuffix, remotePrefix string) error { - s.T().Helper() - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountSuffix, remotePrefix string) error { + suite.T().Helper() + quicksilver := suite.GetQuicksilverApp(suite.chainA) ibcModule := ics.NewIBCModule(quicksilver.InterchainstakingKeeper) portID, err := icatypes.NewControllerPortID(chainID + "." + accountSuffix) @@ -304,22 +304,22 @@ func (s *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountSuffi return err } - quicksilver.InterchainstakingKeeper.SetConnectionForPort(s.chainA.GetContext(), connectionID, portID) + quicksilver.InterchainstakingKeeper.SetConnectionForPort(suite.chainA.GetContext(), connectionID, portID) - channelID := quicksilver.IBCKeeper.ChannelKeeper.GenerateChannelIdentifier(s.chainA.GetContext()) - quicksilver.IBCKeeper.ChannelKeeper.SetChannel(s.chainA.GetContext(), portID, channelID, channeltypes.Channel{State: channeltypes.OPEN, Ordering: channeltypes.ORDERED, Counterparty: channeltypes.Counterparty{PortId: icatypes.PortID, ChannelId: channelID}, ConnectionHops: []string{connectionID}}) + channelID := quicksilver.IBCKeeper.ChannelKeeper.GenerateChannelIdentifier(suite.chainA.GetContext()) + quicksilver.IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portID, channelID, channeltypes.Channel{State: channeltypes.OPEN, Ordering: channeltypes.ORDERED, Counterparty: channeltypes.Counterparty{PortId: icatypes.PortID, ChannelId: channelID}, ConnectionHops: []string{connectionID}}) - quicksilver.IBCKeeper.ChannelKeeper.SetNextSequenceSend(s.chainA.GetContext(), portID, channelID, 1) - quicksilver.ICAControllerKeeper.SetActiveChannelID(s.chainA.GetContext(), connectionID, portID, channelID) + quicksilver.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), portID, channelID, 1) + quicksilver.ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), connectionID, portID, channelID) key, err := quicksilver.InterchainstakingKeeper.ScopedKeeper().NewCapability( - s.chainA.GetContext(), + suite.chainA.GetContext(), host.ChannelCapabilityPath(portID, channelID), ) if err != nil { return err } err = quicksilver.GetScopedIBCKeeper().ClaimCapability( - s.chainA.GetContext(), + suite.chainA.GetContext(), key, host.ChannelCapabilityPath(portID, channelID), ) @@ -328,14 +328,14 @@ func (s *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountSuffi } key, err = quicksilver.InterchainstakingKeeper.ScopedKeeper().NewCapability( - s.chainA.GetContext(), + suite.chainA.GetContext(), host.PortPath(portID), ) if err != nil { return err } err = quicksilver.GetScopedIBCKeeper().ClaimCapability( - s.chainA.GetContext(), + suite.chainA.GetContext(), key, host.PortPath(portID), ) @@ -347,33 +347,30 @@ func (s *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountSuffi if err != nil { return err } - quicksilver.ICAControllerKeeper.SetInterchainAccountAddress(s.chainA.GetContext(), connectionID, portID, addr) - return ibcModule.OnChanOpenAck(s.chainA.GetContext(), portID, channelID, "", "") + quicksilver.ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), connectionID, portID, addr) + return ibcModule.OnChanOpenAck(suite.chainA.GetContext(), portID, channelID, "", "") } -func (s *KeeperTestSuite) setupTestProtocolData() { +func (suite *KeeperTestSuite) setupTestProtocolData() { // connection type for ibc testsuite chainB - s.addProtocolData( + suite.addProtocolData( types.ProtocolDataTypeConnection, - fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d}", s.path.EndpointB.ConnectionID, s.chainB.ChainID, 0), - s.chainB.ChainID, + []byte(fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d}", suite.path.EndpointB.ConnectionID, suite.chainB.ChainID, 0)), ) // osmosis params - s.addProtocolData( + suite.addProtocolData( types.ProtocolDataTypeOsmosisParams, - fmt.Sprintf("{\"ChainID\": %q}", "osmosis-1"), - types.OsmosisParamsKey, + []byte(fmt.Sprintf("{\"ChainID\": %q, \"BaseDenom\": %q, \"BaseChain\": %q}", "osmosis-1", "uosmo", "osmosis-1")), ) // osmosis test chain - s.addProtocolData( + suite.addProtocolData( types.ProtocolDataTypeConnection, - fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d}", "connection-77002", "osmosis-1", 0), - "osmosis-1", + []byte(fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d}", "connection-77002", "osmosis-1", 0)), ) // osmosis test pool - s.addProtocolData( + suite.addProtocolData( types.ProtocolDataTypeOsmosisPool, - fmt.Sprintf( + []byte(fmt.Sprintf( "{\"poolid\":%d,\"poolname\":%q,\"pooltype\":\"balancer\",\"zones\":{%q:%q,%q:%q}}", 1, "atom/osmo", @@ -381,52 +378,55 @@ func (s *KeeperTestSuite) setupTestProtocolData() { "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", "osmosis-1", "ibc/15E9C5CF5969080539DB395FA7D9C0868265217EFC528433671AAF9B1912D159", - ), - "1", + )), ) // atom (cosmoshub) on osmosis - s.addProtocolData( + suite.addProtocolData( types.ProtocolDataTypeLiquidToken, - fmt.Sprintf( + []byte(fmt.Sprintf( "{\"chainid\":%q,\"registeredzonechainid\":%q,\"ibcdenom\":%q,\"qassetdenom\":%q}", "osmosis-1", "cosmoshub-4", "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", "uqatom", - ), - "osmosis-1/ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", + )), ) // atom (cosmoshub) on local chain - s.addProtocolData(types.ProtocolDataTypeLiquidToken, - fmt.Sprintf( + suite.addProtocolData(types.ProtocolDataTypeLiquidToken, + []byte(fmt.Sprintf( "{\"chainid\":%q,\"registeredzonechainid\":%q,\"ibcdenom\":%q,\"qassetdenom\":%q}", "testchain1", "cosmoshub-4", "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", "uqatom", - ), - "testchain1/ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3") + )), + ) } -func (s *KeeperTestSuite) addProtocolData(dataType types.ProtocolDataType, data, key string) { - s.T().Helper() +func (suite *KeeperTestSuite) addProtocolData(dataType types.ProtocolDataType, data []byte) { + suite.T().Helper() pd := types.ProtocolData{ Type: types.ProtocolDataType_name[int32(dataType)], Data: []byte(data), } - s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper.SetProtocolData(s.chainA.GetContext(), key, &pd) + upd, err := types.UnmarshalProtocolData(dataType, pd.Data) + if err != nil { + panic(err) + } + + suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper.SetProtocolData(suite.chainA.GetContext(), upd.GenerateKey(), &pd) } -func (s *KeeperTestSuite) setupTestDeposits() { - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) setupTestDeposits() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) // add deposit to chainB zone - zone, found := quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) - s.addReceipt( + suite.addReceipt( &zone, testAddress, "testTxHash03", @@ -434,10 +434,10 @@ func (s *KeeperTestSuite) setupTestDeposits() { ) // add deposit to cosmos zone - zone, found = quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), "cosmoshub-4") - s.Require().True(found) + zone, found = quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), "cosmoshub-4") + suite.Require().True(found) - s.addReceipt( + suite.addReceipt( &zone, testAddress, "testTxHash01", @@ -445,10 +445,10 @@ func (s *KeeperTestSuite) setupTestDeposits() { ) // add deposit to osmosis zone - zone, found = quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), "osmosis-1") - s.Require().True(found) + zone, found = quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), "osmosis-1") + suite.Require().True(found) - s.addReceipt( + suite.addReceipt( &zone, testAddress, "testTxHash02", @@ -456,7 +456,7 @@ func (s *KeeperTestSuite) setupTestDeposits() { ) } -func (s *KeeperTestSuite) addReceipt(zone *icstypes.Zone, sender, hash string, coins sdk.Coins) { +func (suite *KeeperTestSuite) addReceipt(zone *icstypes.Zone, sender, hash string, coins sdk.Coins) { receipt := icstypes.Receipt{ ChainId: zone.ChainId, Sender: sender, @@ -464,7 +464,7 @@ func (s *KeeperTestSuite) addReceipt(zone *icstypes.Zone, sender, hash string, c Amount: coins, } - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetReceipt(s.chainA.GetContext(), receipt) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetReceipt(suite.chainA.GetContext(), receipt) delegationAddress := utils.GenerateAccAddressForTestWithPrefix("cosmos") validatorAddress := utils.GenerateValAddressForTestWithPrefix("cosmos") @@ -475,18 +475,18 @@ func (s *KeeperTestSuite) addReceipt(zone *icstypes.Zone, sender, hash string, c Height: 1, RedelegationEnd: 101, } - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetDelegation(s.chainA.GetContext(), zone, delegation) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetDelegation(suite.chainA.GetContext(), zone, delegation) } -func (s *KeeperTestSuite) setupTestIntents() { - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) setupTestIntents() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) // chainB - zone, found := quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) - vals := quicksilver.InterchainstakingKeeper.GetValidators(s.chainA.GetContext(), s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) + vals := quicksilver.InterchainstakingKeeper.GetValidators(suite.chainA.GetContext(), suite.chainB.ChainID) - s.addIntent( + suite.addIntent( testAddress, zone, icstypes.ValidatorIntents{ @@ -506,17 +506,17 @@ func (s *KeeperTestSuite) setupTestIntents() { ) } -func (s *KeeperTestSuite) addIntent(address string, zone icstypes.Zone, intents icstypes.ValidatorIntents) { +func (suite *KeeperTestSuite) addIntent(address string, zone icstypes.Zone, intents icstypes.ValidatorIntents) { intent := icstypes.DelegatorIntent{ Delegator: address, Intents: intents, } - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetDelegatorIntent(s.chainA.GetContext(), &zone, intent, false) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetDelegatorIntent(suite.chainA.GetContext(), &zone, intent, false) } -func (s *KeeperTestSuite) setupTestClaims() { +func (suite *KeeperTestSuite) setupTestClaims() { // add some claims - s.addClaim( + suite.addClaim( testAddress, "cosmoshub-4", cmtypes.ClaimTypeLiquidToken, @@ -524,7 +524,7 @@ func (s *KeeperTestSuite) setupTestClaims() { 40000000, ) - s.addClaim( + suite.addClaim( "quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure", "cosmoshub-4", cmtypes.ClaimTypeLiquidToken, @@ -533,7 +533,7 @@ func (s *KeeperTestSuite) setupTestClaims() { ) } -func (s *KeeperTestSuite) addClaim(address, chainID string, claimType cmtypes.ClaimType, sourceChainID string, amount uint64) { +func (suite *KeeperTestSuite) addClaim(address, chainID string, claimType cmtypes.ClaimType, sourceChainID string, amount uint64) { claim := cmtypes.Claim{ UserAddress: address, ChainId: chainID, @@ -541,5 +541,5 @@ func (s *KeeperTestSuite) addClaim(address, chainID string, claimType cmtypes.Cl SourceChainId: sourceChainID, Amount: amount, } - s.GetQuicksilverApp(s.chainA).ClaimsManagerKeeper.SetClaim(s.chainA.GetContext(), &claim) + suite.GetQuicksilverApp(suite.chainA).ClaimsManagerKeeper.SetClaim(suite.chainA.GetContext(), &claim) } diff --git a/x/participationrewards/keeper/msg_server_test.go b/x/participationrewards/keeper/msg_server_test.go index c306ae827..54e0ebfa7 100644 --- a/x/participationrewards/keeper/msg_server_test.go +++ b/x/participationrewards/keeper/msg_server_test.go @@ -2,7 +2,6 @@ package keeper_test import ( "encoding/json" - "fmt" "time" "cosmossdk.io/math" @@ -20,9 +19,9 @@ import ( "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { +func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { // TODO: these tests ought to validate the error received. - appA := s.GetQuicksilverApp(s.chainA) + appA := suite.GetQuicksilverApp(suite.chainA) msg := types.MsgSubmitClaim{} tests := []struct { @@ -42,8 +41,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { func() { msg = types.MsgSubmitClaim{ UserAddress: utils.GenerateAccAddressForTest().String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainB.ChainID, + Zone: suite.chainB.ChainID, + SrcZone: suite.chainB.ChainID, ClaimType: cmtypes.ClaimTypeOsmosisPool, Proofs: []*cmtypes.Proof{ { @@ -78,7 +77,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { }, } bz, err := lockedResp.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) msg = types.MsgSubmitClaim{ UserAddress: userAddress.String(), @@ -118,7 +117,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { }, } bz, err := lockedResp.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) msg = types.MsgSubmitClaim{ UserAddress: userAddress.String(), @@ -156,7 +155,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { ), } bz, err := locked.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) msg = types.MsgSubmitClaim{ UserAddress: userAddress.String(), @@ -188,7 +187,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { Amount: math.NewInt(0), } bz, err := cd.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) msg = types.MsgSubmitClaim{ UserAddress: address.String(), @@ -220,7 +219,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { Amount: math.NewInt(0), } bz, err := cd.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) msg = types.MsgSubmitClaim{ UserAddress: address.String(), @@ -245,9 +244,9 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { for _, tt := range tests { tt := tt - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() params := appA.ParticipationRewardsKeeper.GetParams(ctx) params.ClaimsEnabled = true appA.ParticipationRewardsKeeper.SetParams(ctx, params) @@ -255,20 +254,20 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { k := keeper.NewMsgServerImpl(appA.ParticipationRewardsKeeper) resp, err := k.SubmitClaim(sdk.WrapSDKContext(ctx), &msg) if tt.wantErr != "" { - s.Require().Errorf(err, tt.wantErr) - s.Require().Nil(resp) - s.T().Logf("Error: %v", err) + suite.Require().Errorf(err, tt.wantErr) + suite.Require().Nil(resp) + suite.T().Logf("Error: %v", err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.want, resp) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.want, resp) }) } } -func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { +func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { address := utils.GenerateAccAddressForTest() var msg *types.MsgSubmitClaim @@ -298,8 +297,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainA.ChainID, + Zone: suite.chainB.ChainID, + SrcZone: suite.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -319,8 +318,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { { "local_callback_value_invalid_denom", func(ctx sdk.Context, appA *app.Quicksilver) { - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) - s.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) }, func(ctx sdk.Context, appA *app.Quicksilver) *types.MsgSubmitClaim { key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("uqatom")) @@ -336,8 +335,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainA.ChainID, + Zone: suite.chainB.ChainID, + SrcZone: suite.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -357,20 +356,22 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { { "local_callback_value_valid_denom", func(ctx sdk.Context, appA *app.Quicksilver) { - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) - s.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) // add uqatom to the list of allowed denoms for this zone - blob, err := json.Marshal(types.LiquidAllowedDenomProtocolData{ - ChainID: s.chainA.ChainID, + rawPd := types.LiquidAllowedDenomProtocolData{ + ChainID: suite.chainA.ChainID, IbcDenom: "uqatom", QAssetDenom: "uqatom", - RegisteredZoneChainID: s.chainB.ChainID, - }) - s.Require().NoError(err) + RegisteredZoneChainID: suite.chainB.ChainID, + } + + blob, err := json.Marshal(rawPd) + suite.Require().NoError(err) pd := types.NewProtocolData(types.ProtocolDataType_name[int32(types.ProtocolDataTypeLiquidToken)], blob) - appA.ParticipationRewardsKeeper.SetProtocolData(ctx, fmt.Sprintf("%s/uqatom", s.chainA.ChainID), pd) + appA.ParticipationRewardsKeeper.SetProtocolData(ctx, rawPd.GenerateKey(), pd) }, func(ctx sdk.Context, appA *app.Quicksilver) *types.MsgSubmitClaim { key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("uqatom")) @@ -386,8 +387,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainA.ChainID, + Zone: suite.chainB.ChainID, + SrcZone: suite.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -404,9 +405,9 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { "", []cmtypes.Claim{{ UserAddress: address.String(), - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, - SourceChainId: s.chainA.ChainID, + SourceChainId: suite.chainA.ChainID, Amount: 100, }}, }, @@ -414,23 +415,23 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { for _, tt := range tests { tt := tt - s.Run(tt.name, func() { - s.SetupTest() + suite.Run(tt.name, func() { + suite.SetupTest() - appA := s.GetQuicksilverApp(s.chainA) + appA := suite.GetQuicksilverApp(suite.chainA) // override disabled proof verification; lets test actual proofs :) appA.ParticipationRewardsKeeper.ValidateProofOps = utils.ValidateProofOps appA.ParticipationRewardsKeeper.ValidateSelfProofOps = utils.ValidateSelfProofOps - s.coordinator.CommitNBlocks(s.chainA, 3) - ctx := s.chainA.GetContext() + suite.coordinator.CommitNBlocks(suite.chainA, 3) + ctx := suite.chainA.GetContext() tt.malleate(ctx, appA) - s.coordinator.CommitNBlocks(s.chainA, 3) - ctx = s.chainA.GetContext() - s.Require().NoError(appA.ClaimsManagerKeeper.StoreSelfConsensusState(ctx, "epoch")) - s.coordinator.CommitNBlocks(s.chainA, 1) + suite.coordinator.CommitNBlocks(suite.chainA, 3) + ctx = suite.chainA.GetContext() + suite.Require().NoError(appA.ClaimsManagerKeeper.StoreSelfConsensusState(ctx, "epoch")) + suite.coordinator.CommitNBlocks(suite.chainA, 1) - ctx = s.chainA.GetContext() + ctx = suite.chainA.GetContext() msg = tt.generate(ctx, appA) params := appA.ParticipationRewardsKeeper.GetParams(ctx) params.ClaimsEnabled = true @@ -440,22 +441,22 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { k := keeper.NewMsgServerImpl(appA.ParticipationRewardsKeeper) resp, err := k.SubmitClaim(sdk.WrapSDKContext(ctx), msg) if tt.wantErr != "" { - s.Require().Errorf(err, tt.wantErr) - s.Require().Nil(resp) - s.T().Logf("Error: %v", err) + suite.Require().Errorf(err, tt.wantErr) + suite.Require().Nil(resp) + suite.T().Logf("Error: %v", err) return } for _, expectedClaim := range tt.claims { actualClaim, found := appA.ClaimsManagerKeeper.GetClaim(ctx, expectedClaim.ChainId, expectedClaim.UserAddress, expectedClaim.Module, expectedClaim.SourceChainId) - s.Require().True(found) - s.Require().Equal(expectedClaim.Amount, actualClaim.Amount) + suite.Require().True(found) + suite.Require().Equal(expectedClaim.Amount, actualClaim.Amount) } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.want, resp) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.want, resp) }) } } diff --git a/x/participationrewards/keeper/proposal_handler.go b/x/participationrewards/keeper/proposal_handler.go index 628718627..898c8dc58 100644 --- a/x/participationrewards/keeper/proposal_handler.go +++ b/x/participationrewards/keeper/proposal_handler.go @@ -28,7 +28,7 @@ func HandleAddProtocolDataProposal(ctx sdk.Context, k *Keeper, p *types.AddProto return err } - k.SetProtocolData(ctx, p.Key, protocolData) + k.SetProtocolData(ctx, pd.GenerateKey(), protocolData) return nil } diff --git a/x/participationrewards/keeper/proposal_handler_test.go b/x/participationrewards/keeper/proposal_handler_test.go index 742c80024..c36641da7 100644 --- a/x/participationrewards/keeper/proposal_handler_test.go +++ b/x/participationrewards/keeper/proposal_handler_test.go @@ -7,8 +7,8 @@ import ( "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -func (s *KeeperTestSuite) TestHandleAddProtocolDataProposal() { - appA := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) TestHandleAddProtocolDataProposal() { + appA := suite.GetQuicksilverApp(suite.chainA) prop := types.AddProtocolDataProposal{} tests := []struct { @@ -78,7 +78,7 @@ func (s *KeeperTestSuite) TestHandleAddProtocolDataProposal() { { "valid_prop", func() { - connpdstr := fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d, \"prefix\": \"cosmos\"}", s.path.EndpointB.ConnectionID, s.chainB.ChainID, 0) + connpdstr := fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d, \"prefix\": \"cosmos\"}", suite.path.EndpointB.ConnectionID, suite.chainB.ChainID, 0) prop = types.AddProtocolDataProposal{ Title: "Add connection protocol for test chain B", @@ -92,17 +92,17 @@ func (s *KeeperTestSuite) TestHandleAddProtocolDataProposal() { }, } for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() k := appA.ParticipationRewardsKeeper - err := keeper.HandleAddProtocolDataProposal(s.chainA.GetContext(), k, &prop) + err := keeper.HandleAddProtocolDataProposal(suite.chainA.GetContext(), k, &prop) if tt.wantErr { - s.Require().Error(err) - s.T().Logf("Error: %v", err) + suite.Require().Error(err) + suite.T().Logf("Error: %v", err) return } - s.Require().NoError(err) + suite.Require().NoError(err) }) } } diff --git a/x/participationrewards/keeper/protocol_data.go b/x/participationrewards/keeper/protocol_data.go index a6384f84a..c5345cfb3 100644 --- a/x/participationrewards/keeper/protocol_data.go +++ b/x/participationrewards/keeper/protocol_data.go @@ -11,7 +11,7 @@ import ( func (k *Keeper) GetProtocolData(ctx sdk.Context, pdType types.ProtocolDataType, key string) (types.ProtocolData, bool) { data := types.ProtocolData{} store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixProtocolData) - bz := store.Get(types.GetProtocolDataKey(pdType, key)) + bz := store.Get(types.GetProtocolDataKey(pdType, []byte(key))) if len(bz) == 0 { return data, false } @@ -20,8 +20,8 @@ func (k *Keeper) GetProtocolData(ctx sdk.Context, pdType types.ProtocolDataType, return data, true } -// SetProtocolData sets protocol data info. -func (k *Keeper) SetProtocolData(ctx sdk.Context, key string, data *types.ProtocolData) { +// SetProtocolData set protocol data info +func (k Keeper) SetProtocolData(ctx sdk.Context, key []byte, data *types.ProtocolData) { if data == nil { k.Logger(ctx).Error("protocol data not set; value is nil") return @@ -39,13 +39,13 @@ func (k *Keeper) SetProtocolData(ctx sdk.Context, key string, data *types.Protoc } // DeleteProtocolData deletes protocol data info. -func (k *Keeper) DeleteProtocolData(ctx sdk.Context, key string) { +func (k *Keeper) DeleteProtocolData(ctx sdk.Context, key []byte) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixProtocolData) - store.Delete([]byte(key)) + store.Delete(key) } // IteratePrefixedProtocolDatas iterate through protocol data with the given prefix and perform the provided function. -func (k *Keeper) IteratePrefixedProtocolDatas(ctx sdk.Context, key []byte, fn func(index int64, data types.ProtocolData) (stop bool)) { +func (k *Keeper) IteratePrefixedProtocolDatas(ctx sdk.Context, key []byte, fn func(index int64, key []byte, data types.ProtocolData) (stop bool)) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixProtocolData) iterator := sdk.KVStorePrefixIterator(store, key) defer iterator.Close() @@ -54,7 +54,7 @@ func (k *Keeper) IteratePrefixedProtocolDatas(ctx sdk.Context, key []byte, fn fu for ; iterator.Valid(); iterator.Next() { data := types.ProtocolData{} k.cdc.MustUnmarshal(iterator.Value(), &data) - stop := fn(i, data) + stop := fn(i, iterator.Key(), data) if stop { break } diff --git a/x/participationrewards/keeper/rewards_holdings_test.go b/x/participationrewards/keeper/rewards_holdings_test.go index 9ad301c4b..afbc03359 100644 --- a/x/participationrewards/keeper/rewards_holdings_test.go +++ b/x/participationrewards/keeper/rewards_holdings_test.go @@ -10,7 +10,7 @@ import ( "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { +func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { user1 := utils.GenerateAccAddressForTest() user2 := utils.GenerateAccAddressForTest() @@ -24,7 +24,7 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { { "zero claims; no allocation", func(ctx sdk.Context, appA *app.Quicksilver) { - zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.HoldingsAllocation = 0 appA.InterchainstakingKeeper.SetZone(ctx, &zone) }, @@ -35,11 +35,11 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { { "zero relevant claims; 64k allocation, all returned", func(ctx sdk.Context, appA *app.Quicksilver) { - zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.HoldingsAllocation = 64000 appA.InterchainstakingKeeper.SetZone(ctx, &zone) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: "otherchain-1", Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 500}) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: "otherchain-1", Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 1000}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: "otherchain-1", Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 500}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: "otherchain-1", Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 1000}) }, []types.UserAllocation{}, sdk.NewInt(64000), @@ -48,13 +48,13 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { { "valid claims - equal claims", func(ctx sdk.Context, appA *app.Quicksilver) { - zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.HoldingsAllocation = 5000 - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(5000))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(5000))))) appA.InterchainstakingKeeper.SetZone(ctx, &zone) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 2500}) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 2500}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 2500}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 2500}) }, []types.UserAllocation{ { @@ -72,13 +72,13 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { { "valid claims - inequal claims, less than 100%, truncation", func(ctx sdk.Context, appA *app.Quicksilver) { - zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.HoldingsAllocation = 5000 - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(2500))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(2500))))) appA.InterchainstakingKeeper.SetZone(ctx, &zone) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 500}) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 1000}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 500}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 1000}) }, []types.UserAllocation{ { @@ -96,13 +96,13 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { { "valid claims - inequal claims, 100%, truncation", func(ctx sdk.Context, appA *app.Quicksilver) { - zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.HoldingsAllocation = 5000 - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(1500))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(1500))))) appA.InterchainstakingKeeper.SetZone(ctx, &zone) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 500}) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 1000}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 500}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 1000}) }, []types.UserAllocation{ { @@ -121,27 +121,27 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { for _, tt := range tests { tt := tt - s.Run(tt.name, func() { - s.SetupTest() + suite.Run(tt.name, func() { + suite.SetupTest() - appA := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + appA := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() params := appA.ParticipationRewardsKeeper.GetParams(ctx) params.ClaimsEnabled = true appA.ParticipationRewardsKeeper.SetParams(ctx, params) - tt.malleate(s.chainA.GetContext(), appA) + tt.malleate(suite.chainA.GetContext(), appA) - zone, found := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(appA.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) - s.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToModule(ctx, "mint", types.ModuleName, sdk.NewCoins(sdk.NewCoin(appA.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(appA.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) + suite.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToModule(ctx, "mint", types.ModuleName, sdk.NewCoins(sdk.NewCoin(appA.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) allocations, remainder := appA.ParticipationRewardsKeeper.CalcUserHoldingsAllocations(ctx, &zone) - s.Require().ElementsMatch(tt.want, allocations) - s.Require().True(tt.remainder.Equal(remainder)) + suite.Require().ElementsMatch(tt.want, allocations) + suite.Require().True(tt.remainder.Equal(remainder)) }) } } diff --git a/x/participationrewards/keeper/submodule_liquid.go b/x/participationrewards/keeper/submodule_liquid.go index a755b3a87..bb6d15b48 100644 --- a/x/participationrewards/keeper/submodule_liquid.go +++ b/x/participationrewards/keeper/submodule_liquid.go @@ -55,7 +55,7 @@ func (m *LiquidTokensModule) ValidateClaim(ctx sdk.Context, k *Keeper, msg *type return 0, err } - data, found := k.GetProtocolData(ctx, types.ProtocolDataTypeLiquidToken, fmt.Sprintf("%s/%s", msg.SrcZone, denom)) + data, found := k.GetProtocolData(ctx, types.ProtocolDataTypeLiquidToken, fmt.Sprintf("%s_%s", msg.SrcZone, denom)) if !found { // we don't have a record for this denom, but this is okay, we don't want to submit records for every ibc denom. continue diff --git a/x/participationrewards/keeper/submodule_osmosis.go b/x/participationrewards/keeper/submodule_osmosis.go index 186de49fb..4dc40858f 100644 --- a/x/participationrewards/keeper/submodule_osmosis.go +++ b/x/participationrewards/keeper/submodule_osmosis.go @@ -43,7 +43,7 @@ func (m *OsmosisModule) Hooks(ctx sdk.Context, k *Keeper) { return } - k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeOsmosisPool), func(idx int64, data types.ProtocolData) bool { + k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeOsmosisPool), func(idx int64, _ []byte, data types.ProtocolData) bool { ipool, err := types.UnmarshalProtocolData(types.ProtocolDataTypeOsmosisPool, data.Data) if err != nil { return false diff --git a/x/participationrewards/types/keys.go b/x/participationrewards/types/keys.go index ddd4ce106..4ab00fd0f 100644 --- a/x/participationrewards/types/keys.go +++ b/x/participationrewards/types/keys.go @@ -19,8 +19,8 @@ const ( var KeyPrefixProtocolData = []byte{0x00} -func GetProtocolDataKey(pdType ProtocolDataType, key string) []byte { - return append(sdk.Uint64ToBigEndian(uint64(pdType)), []byte(key)...) +func GetProtocolDataKey(pdType ProtocolDataType, key []byte) []byte { + return append(sdk.Uint64ToBigEndian(uint64(pdType)), key...) } func GetPrefixProtocolDataKey(pdType ProtocolDataType) []byte { diff --git a/x/participationrewards/types/proposals.go b/x/participationrewards/types/proposals.go index 02a2b5f4a..c8dd7ebb0 100644 --- a/x/participationrewards/types/proposals.go +++ b/x/participationrewards/types/proposals.go @@ -36,14 +36,24 @@ func (m *AddProtocolDataProposal) ValidateBasic() error { errors["Type"] = ErrUndefinedAttribute } - if m.Key == "" { - errors["Key"] = ErrUndefinedAttribute - } + // Key is now a deprecated field and unused. + // if len(m.Key) == 0 { + // errors["Key"] = ErrUndefinedAttribute + // } if len(m.Data) == 0 { errors["Data"] = ErrUndefinedAttribute } + pd, err := UnmarshalProtocolData(ProtocolDataType(ProtocolDataType_value[m.Type]), m.Data) + if err != nil { + errors["Data"] = err + } else { + if err = pd.ValidateBasic(); err != nil { + errors["Data"] = err + } + } + if len(errors) > 0 { return multierror.New(errors) } @@ -58,6 +68,5 @@ Title: %s Description: %s Type: %s Data: %s -Key: %s -`, m.Title, m.Description, m.Type, m.Data, m.Key) +`, m.Title, m.Description, m.Type, m.Data) } diff --git a/x/participationrewards/types/proposals_test.go b/x/participationrewards/types/proposals_test.go index 3df195a4a..17cb72b3f 100644 --- a/x/participationrewards/types/proposals_test.go +++ b/x/participationrewards/types/proposals_test.go @@ -55,7 +55,6 @@ func TestAddProtocolDataProposal_ValidateBasic(t *testing.T) { Description: "A new protocol for testing protocols", Protocol: "TestProtocol", Type: "", - Key: "", Data: nil, }, true, @@ -67,7 +66,6 @@ func TestAddProtocolDataProposal_ValidateBasic(t *testing.T) { Description: "A new protocol for testing protocols", Protocol: "TestProtocol", Type: "TestType", - Key: "", Data: nil, }, true, @@ -79,7 +77,6 @@ func TestAddProtocolDataProposal_ValidateBasic(t *testing.T) { Description: "A new protocol for testing protocols", Protocol: "TestProtocol", Type: "TestType", - Key: "TestKey", Data: nil, }, true, @@ -90,8 +87,7 @@ func TestAddProtocolDataProposal_ValidateBasic(t *testing.T) { Title: "Valid Protocol Data", Description: "A valid protocol that is valid", Protocol: "ValidProtocol", - Type: "liquidtoken", - Key: "liquid", + Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeLiquidToken)], Data: []byte(validLiquidData), }, false, @@ -146,7 +142,6 @@ Data: { "ibcdenom": "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", "qassetdenom": "uqstake" } -Key: liquid ` t.Run("stringer", func(t *testing.T) { diff --git a/x/participationrewards/types/protocol_data.go b/x/participationrewards/types/protocol_data.go index b966f5111..dde9b8eff 100644 --- a/x/participationrewards/types/protocol_data.go +++ b/x/participationrewards/types/protocol_data.go @@ -67,6 +67,7 @@ func UnmarshalProtocolData(datatype ProtocolDataType, data json.RawMessage) (Pro type ProtocolDataI interface { ValidateBasic() error + GenerateKey() []byte } // ConnectionProtocolData defines state for connection tracking. @@ -100,6 +101,10 @@ func (cpd *ConnectionProtocolData) ValidateBasic() error { return nil } +func (cpd ConnectionProtocolData) GenerateKey() []byte { + return []byte(cpd.ChainID) +} + var ( _ ProtocolDataI = &ConnectionProtocolData{} _ ProtocolDataI = &OsmosisPoolProtocolData{} diff --git a/x/participationrewards/types/submodule_liquid.go b/x/participationrewards/types/submodule_liquid.go index b215a2e49..e78bc45a9 100644 --- a/x/participationrewards/types/submodule_liquid.go +++ b/x/participationrewards/types/submodule_liquid.go @@ -48,3 +48,7 @@ func (lpd *LiquidAllowedDenomProtocolData) ValidateBasic() error { return nil } + +func (lpd *LiquidAllowedDenomProtocolData) GenerateKey() []byte { + return []byte(lpd.ChainID + "_" + lpd.IbcDenom) +} diff --git a/x/participationrewards/types/submodule_osmosis.go b/x/participationrewards/types/submodule_osmosis.go index e70982d62..217e4c20e 100644 --- a/x/participationrewards/types/submodule_osmosis.go +++ b/x/participationrewards/types/submodule_osmosis.go @@ -19,12 +19,13 @@ const ( // OsmosisPoolProtocolData defines protocol state to track qAssets locked in // Osmosis pools. type OsmosisPoolProtocolData struct { - PoolID uint64 - PoolName string - LastUpdated time.Time - PoolData json.RawMessage - PoolType string - Zones map[string]string // chainID: IBC/denom + PoolID uint64 + PoolName string + LastUpdated time.Time + PoolData json.RawMessage + PoolType string + Zones map[string]string // chainID: IBC/denom + IsIncentivized bool } func (opd *OsmosisPoolProtocolData) GetPool() (gamm.PoolI, error) { @@ -106,10 +107,16 @@ func (opd *OsmosisPoolProtocolData) ValidateBasic() error { return nil } +func (opd *OsmosisPoolProtocolData) GenerateKey() []byte { + return []byte(fmt.Sprintf("%d", opd.PoolID)) +} + // ----------------------------------------------------- type OsmosisParamsProtocolData struct { - ChainID string + ChainID string + BaseDenom string + BaseChain string } // ValidateBasic satisfies ProtocolDataI and validates basic stateless data. @@ -121,9 +128,21 @@ func (oppd *OsmosisParamsProtocolData) ValidateBasic() error { errs["ChainID"] = ErrUndefinedAttribute } + if oppd.BaseChain == "" { + errs["BaseChain"] = ErrUndefinedAttribute + } + + if oppd.BaseDenom == "" { + errs["BaseDenom"] = ErrUndefinedAttribute + } + if len(errs) > 0 { return multierror.New(errs) } return nil } + +func (oppd *OsmosisParamsProtocolData) GenerateKey() []byte { + return []byte("osmosisparams") +} diff --git a/x/participationrewards/types/submodule_osmosis_test.go b/x/participationrewards/types/submodule_osmosis_test.go index 12a991d81..473da02c8 100644 --- a/x/participationrewards/types/submodule_osmosis_test.go +++ b/x/participationrewards/types/submodule_osmosis_test.go @@ -10,7 +10,9 @@ import ( func TestOsmosisParamsProtocolData_ValidateBasic(t *testing.T) { type fields struct { - ChainID string + ChainID string + BaseChain string + BaseDenom string } tests := []struct { name string @@ -23,9 +25,18 @@ func TestOsmosisParamsProtocolData_ValidateBasic(t *testing.T) { true, }, { - "valid", + "missing-fields", fields{ - "test-01", + ChainID: "test-01", + }, + true, + }, + { + "value", + fields{ + ChainID: "test-01", + BaseDenom: "uosmo", + BaseChain: "test-01", }, false, }, @@ -33,7 +44,9 @@ func TestOsmosisParamsProtocolData_ValidateBasic(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { oppd := types.OsmosisParamsProtocolData{ - ChainID: tt.fields.ChainID, + ChainID: tt.fields.ChainID, + BaseDenom: tt.fields.BaseDenom, + BaseChain: tt.fields.BaseChain, } err := oppd.ValidateBasic() if tt.wantErr { From 6a77679558b0b17d0f73446c80b6402aad0ec8cf Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Fri, 2 Jun 2023 14:39:57 +0100 Subject: [PATCH 10/25] front-port v1.2.13 --- .../interchainquery/v1/query.proto | 2 + x/interchainquery/types/query.pb.go | 130 +++++++++++++----- 2 files changed, 95 insertions(+), 37 deletions(-) diff --git a/proto/quicksilver/interchainquery/v1/query.proto b/proto/quicksilver/interchainquery/v1/query.proto index e98d14055..adf51853c 100644 --- a/proto/quicksilver/interchainquery/v1/query.proto +++ b/proto/quicksilver/interchainquery/v1/query.proto @@ -45,4 +45,6 @@ message GetTxWithProofResponse { tendermint.types.TxProof proof = 3; // ibc-go header to validate txs ibc.lightclients.tendermint.v1.Header header = 4; + // tx_bytes is the byte representation of the queried tx + bytes tx_bytes = 5; } diff --git a/x/interchainquery/types/query.pb.go b/x/interchainquery/types/query.pb.go index 1f3f16b6f..0e1dd423a 100644 --- a/x/interchainquery/types/query.pb.go +++ b/x/interchainquery/types/query.pb.go @@ -151,6 +151,8 @@ type GetTxWithProofResponse struct { Proof *types1.TxProof `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"` // ibc-go header to validate txs Header *types2.Header `protobuf:"bytes,4,opt,name=header,proto3" json:"header,omitempty"` + // tx_bytes is the byte representation of the queried tx + TxBytes []byte `protobuf:"bytes,5,opt,name=tx_bytes,json=txBytes,proto3" json:"tx_bytes,omitempty"` } func (m *GetTxWithProofResponse) Reset() { *m = GetTxWithProofResponse{} } @@ -214,6 +216,13 @@ func (m *GetTxWithProofResponse) GetHeader() *types2.Header { return nil } +func (m *GetTxWithProofResponse) GetTxBytes() []byte { + if m != nil { + return m.TxBytes + } + return nil +} + func init() { proto.RegisterType((*QueryRequestsRequest)(nil), "quicksilver.interchainquery.v1.QueryRequestsRequest") proto.RegisterType((*QueryRequestsResponse)(nil), "quicksilver.interchainquery.v1.QueryRequestsResponse") @@ -225,43 +234,45 @@ func init() { } var fileDescriptor_e4aadfdae61bcbb1 = []byte{ - // 576 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x41, 0x6f, 0xd3, 0x30, - 0x18, 0xad, 0xbb, 0xb1, 0x31, 0xf7, 0x16, 0x6d, 0xa8, 0xab, 0x50, 0xa8, 0x0a, 0x83, 0x6a, 0x12, - 0xb6, 0x5a, 0xca, 0x85, 0xc3, 0x0e, 0x93, 0xc6, 0xe0, 0xb6, 0x85, 0x4a, 0x20, 0x2e, 0x53, 0x92, - 0x9a, 0xd4, 0xa2, 0xb5, 0xd3, 0xf8, 0x4b, 0x94, 0x0a, 0x71, 0xe1, 0x17, 0x20, 0xf1, 0x23, 0xb8, - 0xf3, 0x0b, 0x38, 0xee, 0x38, 0x89, 0x0b, 0x27, 0x84, 0x5a, 0xfe, 0x03, 0x57, 0x14, 0xc7, 0xcd, - 0xd2, 0x22, 0xb1, 0x71, 0x69, 0xed, 0xf8, 0xbd, 0xf7, 0xbd, 0xef, 0xf9, 0x4b, 0xf0, 0xfe, 0x24, - 0xe6, 0xfe, 0x5b, 0xc5, 0x47, 0x09, 0x8b, 0x28, 0x17, 0xc0, 0x22, 0x7f, 0xe8, 0x72, 0x31, 0x89, - 0x59, 0x34, 0xa5, 0x49, 0x87, 0xea, 0x05, 0x09, 0x23, 0x09, 0xd2, 0xb2, 0x4b, 0x58, 0xb2, 0x82, - 0x25, 0x49, 0xa7, 0x71, 0xd7, 0x97, 0x6a, 0x2c, 0x15, 0xf5, 0x5c, 0xc5, 0xa8, 0xeb, 0xf9, 0x9c, - 0x26, 0x1d, 0x8f, 0x81, 0xdb, 0xd1, 0x9b, 0x5c, 0xa4, 0xb1, 0x5f, 0x06, 0x2d, 0xca, 0xe4, 0xa8, - 0xd0, 0x0d, 0xb8, 0x70, 0x81, 0x4b, 0x61, 0xb0, 0x0d, 0x83, 0x85, 0xb4, 0xc0, 0x40, 0x6a, 0xce, - 0xb6, 0x03, 0x19, 0x48, 0xbd, 0xa4, 0xd9, 0xca, 0x3c, 0xbd, 0x1d, 0x48, 0x19, 0x8c, 0x18, 0x75, - 0x43, 0x4e, 0x5d, 0x21, 0x24, 0x68, 0x39, 0x65, 0x4e, 0x29, 0xf7, 0x7c, 0x3a, 0xe2, 0xc1, 0x10, - 0xfc, 0x11, 0x67, 0x02, 0x14, 0x05, 0x26, 0x06, 0x2c, 0x1a, 0x73, 0x01, 0x59, 0xb3, 0x97, 0x3b, - 0x43, 0xe8, 0x5d, 0x91, 0xce, 0x6a, 0x08, 0xc6, 0x44, 0x49, 0x15, 0xa6, 0x21, 0x53, 0xf9, 0x6f, - 0x7e, 0xda, 0x9a, 0xe2, 0xed, 0xd3, 0x0c, 0xec, 0xb0, 0x49, 0xcc, 0x14, 0x28, 0xf3, 0x6f, 0x3d, - 0xc5, 0xf8, 0x32, 0x80, 0x3a, 0x6a, 0xa2, 0x76, 0xad, 0x7b, 0x9f, 0xe4, 0x09, 0x90, 0x2c, 0x2d, - 0xb2, 0x08, 0x5a, 0x27, 0x41, 0x4e, 0xdc, 0x80, 0x19, 0xae, 0x53, 0x62, 0x5a, 0xbb, 0xf8, 0xa6, - 0x76, 0x74, 0xc6, 0x07, 0xf5, 0x6a, 0x13, 0xb5, 0xb7, 0x9c, 0x4d, 0xbd, 0x7f, 0x3e, 0x68, 0x7d, - 0x46, 0x78, 0x67, 0xa5, 0xb6, 0x0a, 0xa5, 0x50, 0xcc, 0x3a, 0xc2, 0x9b, 0x99, 0x3a, 0x67, 0xaa, - 0x8e, 0x9a, 0x6b, 0xed, 0x5a, 0x77, 0x8f, 0xfc, 0xfb, 0xb2, 0x89, 0xd6, 0x39, 0x5c, 0x3f, 0xff, - 0x71, 0xa7, 0xe2, 0x2c, 0xb8, 0xd6, 0xf1, 0x52, 0x0f, 0x55, 0xdd, 0xc3, 0x83, 0x2b, 0x7b, 0xc8, - 0x3d, 0x94, 0x9b, 0x68, 0xfd, 0x46, 0xf8, 0xd6, 0x31, 0x83, 0x7e, 0xfa, 0x92, 0xc3, 0xf0, 0x24, - 0x92, 0xf2, 0x4d, 0x61, 0x75, 0x0f, 0x57, 0x21, 0x35, 0xf9, 0xec, 0x2c, 0xb4, 0x21, 0x2d, 0x34, - 0xfb, 0xa9, 0x53, 0x85, 0xd4, 0x3a, 0xc2, 0x35, 0x48, 0xcf, 0x22, 0xc3, 0x32, 0x5e, 0xee, 0x2d, - 0x79, 0xd1, 0x53, 0x59, 0xa2, 0x15, 0x46, 0xa0, 0x58, 0x5b, 0x14, 0xdf, 0x08, 0xb3, 0xf2, 0xf5, - 0x35, 0x2d, 0xb0, 0x4b, 0x4a, 0x33, 0x92, 0xdf, 0x6a, 0x3f, 0xcd, 0xfd, 0xe5, 0x38, 0xeb, 0x00, - 0x6f, 0x0c, 0x99, 0x3b, 0x60, 0x51, 0x7d, 0xdd, 0x5c, 0x21, 0xf7, 0x7c, 0x52, 0x1e, 0xba, 0xb2, - 0x44, 0xd2, 0x21, 0xcf, 0x34, 0xda, 0x31, 0xac, 0xee, 0x57, 0x84, 0xb7, 0x74, 0xb6, 0x2f, 0xa2, - 0x24, 0xb2, 0xbe, 0x20, 0xbc, 0x79, 0x6a, 0xc2, 0xed, 0x5d, 0xeb, 0x4a, 0x56, 0xc6, 0xaa, 0xf1, - 0xf8, 0x3f, 0x59, 0x79, 0xdf, 0xad, 0x27, 0x1f, 0xbe, 0xfd, 0xfa, 0x54, 0xed, 0x59, 0x5d, 0x7a, - 0x8d, 0x0f, 0x04, 0x67, 0x8a, 0xbe, 0x5b, 0x0c, 0xdd, 0xfb, 0xc3, 0x57, 0xe7, 0x33, 0x1b, 0x5d, - 0xcc, 0x6c, 0xf4, 0x73, 0x66, 0xa3, 0x8f, 0x73, 0xbb, 0x72, 0x31, 0xb7, 0x2b, 0xdf, 0xe7, 0x76, - 0xe5, 0xf5, 0x41, 0xc0, 0x61, 0x18, 0x7b, 0xc4, 0x97, 0x63, 0xca, 0x45, 0xc0, 0x44, 0xcc, 0x61, - 0xfa, 0xd0, 0x8b, 0xf9, 0x68, 0xb0, 0x54, 0x27, 0xfd, 0xab, 0x92, 0xce, 0xda, 0xdb, 0xd0, 0xaf, - 0xd0, 0xa3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xd9, 0xbc, 0x02, 0xb6, 0x04, 0x00, 0x00, + // 595 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x8e, 0xdd, 0x9f, 0xd0, 0x2d, 0x27, 0xab, 0x45, 0x6e, 0x84, 0x4c, 0x14, 0x28, 0x44, 0x95, + 0xd8, 0x55, 0x42, 0xb9, 0x70, 0xe8, 0xa1, 0x52, 0x29, 0xdc, 0x5a, 0x53, 0x09, 0xc4, 0xa5, 0xb2, + 0x9d, 0xc5, 0x59, 0x91, 0xee, 0x3a, 0xde, 0xb1, 0xb5, 0x11, 0xe2, 0xc2, 0x13, 0x20, 0x78, 0x08, + 0xee, 0x3c, 0x01, 0xc7, 0x1e, 0x2b, 0x71, 0xe1, 0x84, 0x50, 0xc2, 0x83, 0x20, 0xaf, 0x37, 0xa9, + 0x13, 0x24, 0x5a, 0x2e, 0xc9, 0x8e, 0xf7, 0x9b, 0x6f, 0xbe, 0xf9, 0x66, 0x6c, 0xb4, 0x33, 0xcc, + 0x58, 0xf4, 0x56, 0xb2, 0x41, 0x4e, 0x53, 0xc2, 0x38, 0xd0, 0x34, 0xea, 0x07, 0x8c, 0x0f, 0x33, + 0x9a, 0x8e, 0x48, 0xde, 0x21, 0xfa, 0x80, 0x93, 0x54, 0x80, 0x70, 0xbc, 0x0a, 0x16, 0x2f, 0x60, + 0x71, 0xde, 0x69, 0xdc, 0x8d, 0x84, 0x3c, 0x13, 0x92, 0x84, 0x81, 0xa4, 0x24, 0x08, 0x23, 0x46, + 0xf2, 0x4e, 0x48, 0x21, 0xe8, 0xe8, 0xa0, 0x24, 0x69, 0xec, 0x54, 0x41, 0xd3, 0x32, 0x25, 0x2a, + 0x09, 0x62, 0xc6, 0x03, 0x60, 0x82, 0x1b, 0x6c, 0xc3, 0x60, 0x41, 0xcd, 0x30, 0xa0, 0xcc, 0xdd, + 0x46, 0x2c, 0x62, 0xa1, 0x8f, 0xa4, 0x38, 0x99, 0xa7, 0xb7, 0x63, 0x21, 0xe2, 0x01, 0x25, 0x41, + 0xc2, 0x48, 0xc0, 0xb9, 0x00, 0x4d, 0x27, 0xcd, 0x2d, 0x61, 0x61, 0x44, 0x06, 0x2c, 0xee, 0x43, + 0x34, 0x60, 0x94, 0x83, 0x24, 0x40, 0x79, 0x8f, 0xa6, 0x67, 0x8c, 0x43, 0xd1, 0xec, 0x65, 0x64, + 0x12, 0x76, 0xaf, 0x70, 0x67, 0xd1, 0x04, 0x23, 0xa2, 0xc2, 0x0a, 0xa3, 0x84, 0xca, 0xf2, 0xb7, + 0xbc, 0x6d, 0x8d, 0xd0, 0xc6, 0x71, 0x01, 0xf6, 0xe9, 0x30, 0xa3, 0x12, 0xa4, 0xf9, 0x77, 0x9e, + 0x22, 0x74, 0x69, 0x80, 0x6b, 0x35, 0xad, 0xf6, 0x7a, 0xf7, 0x3e, 0x2e, 0x1d, 0xc0, 0x85, 0x5b, + 0x78, 0x6a, 0xb4, 0x76, 0x02, 0x1f, 0x05, 0x31, 0x35, 0xb9, 0x7e, 0x25, 0xd3, 0xd9, 0x42, 0x37, + 0xb4, 0xa2, 0x53, 0xd6, 0x73, 0xed, 0xa6, 0xd5, 0x5e, 0xf3, 0xeb, 0x3a, 0x7e, 0xde, 0x6b, 0x7d, + 0xb1, 0xd0, 0xe6, 0x42, 0x6d, 0x99, 0x08, 0x2e, 0xa9, 0x73, 0x80, 0xea, 0x05, 0x3b, 0xa3, 0xd2, + 0xb5, 0x9a, 0x4b, 0xed, 0xf5, 0xee, 0x36, 0xfe, 0xf7, 0xb0, 0xb1, 0xe6, 0xd9, 0x5f, 0x3e, 0xff, + 0x79, 0xa7, 0xe6, 0x4f, 0x73, 0x9d, 0xc3, 0xb9, 0x1e, 0x6c, 0xdd, 0xc3, 0x83, 0x2b, 0x7b, 0x28, + 0x35, 0x54, 0x9b, 0x68, 0x7d, 0xb2, 0xd1, 0xad, 0x43, 0x0a, 0x27, 0xea, 0x25, 0x83, 0xfe, 0x51, + 0x2a, 0xc4, 0x9b, 0x99, 0xd4, 0x6d, 0x64, 0x83, 0x32, 0xfe, 0x6c, 0x4e, 0xb9, 0x41, 0xcd, 0x38, + 0x4f, 0x94, 0x6f, 0x83, 0x72, 0x0e, 0xd0, 0x3a, 0xa8, 0xd3, 0xd4, 0x64, 0x19, 0x2d, 0xf7, 0xe6, + 0xb4, 0xe8, 0xad, 0xac, 0xa4, 0xcd, 0x84, 0xc0, 0xec, 0xec, 0x10, 0xb4, 0x92, 0x14, 0xe5, 0xdd, + 0x25, 0x4d, 0xb0, 0x85, 0x2b, 0x3b, 0x52, 0x4e, 0xf5, 0x44, 0x95, 0xfa, 0x4a, 0x9c, 0xb3, 0x87, + 0x56, 0xfb, 0x34, 0xe8, 0xd1, 0xd4, 0x5d, 0x36, 0x23, 0x64, 0x61, 0x84, 0xab, 0x4b, 0x57, 0xa5, + 0xc8, 0x3b, 0xf8, 0x99, 0x46, 0xfb, 0x26, 0xab, 0x18, 0x1f, 0xa8, 0xd3, 0x70, 0x04, 0x54, 0xba, + 0x2b, 0x4d, 0xab, 0x7d, 0xd3, 0xaf, 0x83, 0xda, 0x2f, 0xc2, 0xee, 0x37, 0x0b, 0xad, 0x69, 0xdb, + 0x5f, 0xa4, 0x79, 0xea, 0x7c, 0xb5, 0x50, 0xfd, 0xd8, 0xf8, 0xbe, 0x7b, 0xad, 0x69, 0x2d, 0x6c, + 0x5c, 0xe3, 0xf1, 0x7f, 0x66, 0x95, 0x96, 0xb4, 0x9e, 0x7c, 0xf8, 0xfe, 0xfb, 0xb3, 0xbd, 0xeb, + 0x74, 0xc9, 0x35, 0xbe, 0x1d, 0x8c, 0x4a, 0xf2, 0x6e, 0xba, 0x8f, 0xef, 0xf7, 0x5f, 0x9d, 0x8f, + 0x3d, 0xeb, 0x62, 0xec, 0x59, 0xbf, 0xc6, 0x9e, 0xf5, 0x71, 0xe2, 0xd5, 0x2e, 0x26, 0x5e, 0xed, + 0xc7, 0xc4, 0xab, 0xbd, 0xde, 0x8b, 0x19, 0xf4, 0xb3, 0x10, 0x47, 0xe2, 0x8c, 0x30, 0x1e, 0x53, + 0x9e, 0x31, 0x18, 0x3d, 0x0c, 0x33, 0x36, 0xe8, 0xcd, 0xd5, 0x51, 0x7f, 0x55, 0xd2, 0x63, 0x08, + 0x57, 0xf5, 0xdb, 0xf5, 0xe8, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x41, 0xda, 0x1f, 0xc7, 0xd1, + 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -457,6 +468,13 @@ func (m *GetTxWithProofResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) _ = i var l int _ = l + if len(m.TxBytes) > 0 { + i -= len(m.TxBytes) + copy(dAtA[i:], m.TxBytes) + i = encodeVarintQuery(dAtA, i, uint64(len(m.TxBytes))) + i-- + dAtA[i] = 0x2a + } if m.Header != nil { { size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) @@ -577,6 +595,10 @@ func (m *GetTxWithProofResponse) Size() (n int) { l = m.Header.Size() n += 1 + l + sovQuery(uint64(l)) } + l = len(m.TxBytes) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -997,6 +1019,40 @@ func (m *GetTxWithProofResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxBytes = append(m.TxBytes[:0], dAtA[iNdEx:postIndex]...) + if m.TxBytes == nil { + m.TxBytes = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) From 058bd085a38d7f3667f5014528f33bc24654be6c Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Mon, 5 Jun 2023 11:07:17 +0100 Subject: [PATCH 11/25] remove balancerPoolPretty json marshal/unmarshal, as we deal with raw KV store objects; switch to native bech32 decode/encode as we dont expect prefix of pools to match sdk.GetConfig().Bech32Prefix --- .../gamm/pool-models/balancer/marshal.go | 92 +++++++++---------- .../gamm/pool-models/balancer/pool.go | 3 +- .../gamm/pool-models/stableswap/pool.go | 3 +- 3 files changed, 48 insertions(+), 50 deletions(-) diff --git a/osmosis-types/gamm/pool-models/balancer/marshal.go b/osmosis-types/gamm/pool-models/balancer/marshal.go index 4f99c68f4..0d3afa414 100644 --- a/osmosis-types/gamm/pool-models/balancer/marshal.go +++ b/osmosis-types/gamm/pool-models/balancer/marshal.go @@ -2,24 +2,20 @@ package balancer import ( "encoding/json" - "errors" - "strings" - - sdk "github.com/cosmos/cosmos-sdk/types" ) -type balancerPoolPretty struct { - Address sdk.AccAddress `json:"address" yaml:"address"` - Id uint64 `json:"id" yaml:"id"` - PoolParams PoolParams `json:"pool_params" yaml:"pool_params"` - FuturePoolGovernor string `json:"future_pool_governor" yaml:"future_pool_governor"` - TotalWeight sdk.Dec `json:"total_weight" yaml:"total_weight"` - TotalShares sdk.Coin `json:"total_shares" yaml:"total_shares"` - PoolAssets []PoolAsset `json:"pool_assets" yaml:"pool_assets"` -} +// type balancerPoolPretty struct { +// Address sdk.AccAddress `json:"address" yaml:"address"` +// Id uint64 `json:"id" yaml:"id"` +// PoolParams PoolParams `json:"pool_params" yaml:"pool_params"` +// FuturePoolGovernor string `json:"future_pool_governor" yaml:"future_pool_governor"` +// TotalWeight sdk.Dec `json:"total_weight" yaml:"total_weight"` +// TotalShares sdk.Coin `json:"total_shares" yaml:"total_shares"` +// PoolAssets []PoolAsset `json:"pool_assets" yaml:"pool_assets"` +// } func (p Pool) String() string { - out, err := p.MarshalJSON() + out, err := json.Marshal(p) if err != nil { panic(err) } @@ -27,44 +23,44 @@ func (p Pool) String() string { } // MarshalJSON returns the JSON representation of a Pool. -func (p Pool) MarshalJSON() ([]byte, error) { - if len(strings.TrimSpace(p.Address)) == 0 { - return nil, errors.New("empty address string is not allowed") - } +// func (p Pool) MarshalJSON() ([]byte, error) { +// if len(strings.TrimSpace(p.Address)) == 0 { +// return nil, errors.New("empty address string is not allowed") +// } - accAddr, err := sdk.GetFromBech32(p.Address, "osmo") - // accAddr, err := sdk.AccAddressFromBech32(p.Address) - if err != nil { - return nil, err - } +// accAddr, err := sdk.GetFromBech32(p.Address, "osmo") +// // accAddr, err := sdk.AccAddressFromBech32(p.Address) +// if err != nil { +// return nil, err +// } - decTotalWeight := sdk.NewDecFromInt(p.TotalWeight) +// decTotalWeight := sdk.NewDecFromInt(p.TotalWeight) - return json.Marshal(balancerPoolPretty{ - Address: accAddr, - Id: p.Id, - PoolParams: p.PoolParams, - FuturePoolGovernor: p.FuturePoolGovernor, - TotalWeight: decTotalWeight, - TotalShares: p.TotalShares, - PoolAssets: p.PoolAssets, - }) -} +// return json.Marshal(balancerPoolPretty{ +// Address: accAddr, +// Id: p.Id, +// PoolParams: p.PoolParams, +// FuturePoolGovernor: p.FuturePoolGovernor, +// TotalWeight: decTotalWeight, +// TotalShares: p.TotalShares, +// PoolAssets: p.PoolAssets, +// }) +// } // UnmarshalJSON unmarshals raw JSON bytes into a Pool. -func (p *Pool) UnmarshalJSON(bz []byte) error { - var alias balancerPoolPretty - if err := json.Unmarshal(bz, &alias); err != nil { - return err - } +// func (p *Pool) UnmarshalJSON(bz []byte) error { +// var alias balancerPoolPretty +// if err := json.Unmarshal(bz, &alias); err != nil { +// return err +// } - p.Address = alias.Address.String() - p.Id = alias.Id - p.PoolParams = alias.PoolParams - p.FuturePoolGovernor = alias.FuturePoolGovernor - p.TotalWeight = alias.TotalWeight.RoundInt() - p.TotalShares = alias.TotalShares - p.PoolAssets = alias.PoolAssets +// p.Address = alias.Address.String() +// p.Id = alias.Id +// p.PoolParams = alias.PoolParams +// p.FuturePoolGovernor = alias.FuturePoolGovernor +// p.TotalWeight = alias.TotalWeight.RoundInt() +// p.TotalShares = alias.TotalShares +// p.PoolAssets = alias.PoolAssets - return nil -} +// return nil +// } diff --git a/osmosis-types/gamm/pool-models/balancer/pool.go b/osmosis-types/gamm/pool-models/balancer/pool.go index 23514e7c2..79eee1e18 100644 --- a/osmosis-types/gamm/pool-models/balancer/pool.go +++ b/osmosis-types/gamm/pool-models/balancer/pool.go @@ -9,6 +9,7 @@ import ( sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/internal/cfmm_common" @@ -74,7 +75,7 @@ func NewBalancerPool(poolId uint64, balancerPoolParams PoolParams, assets []Pool // GetAddress returns the address of a pool. // If the pool address is not bech32 valid, it returns an empty address. func (p Pool) GetAddress() sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(p.Address) + _, addr, err := bech32.DecodeAndConvert(p.Address) if err != nil { panic(fmt.Sprintf("could not bech32 decode address of pool with id: %d", p.GetId())) } diff --git a/osmosis-types/gamm/pool-models/stableswap/pool.go b/osmosis-types/gamm/pool-models/stableswap/pool.go index 37498cc50..faa5de210 100644 --- a/osmosis-types/gamm/pool-models/stableswap/pool.go +++ b/osmosis-types/gamm/pool-models/stableswap/pool.go @@ -8,6 +8,7 @@ import ( sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/internal/cfmm_common" @@ -41,7 +42,7 @@ func NewStableswapPool(poolId uint64, stableswapPoolParams PoolParams, initialLi } func (p Pool) GetAddress() sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(p.Address) + _, addr, err := bech32.DecodeAndConvert(p.Address) if err != nil { panic(fmt.Sprintf("could not bech32 decode address of pool with id: %d", p.GetId())) } From 5502cb3751b13710e2266f4c5e4c961bc768ee29 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Tue, 6 Jun 2023 00:14:24 +0100 Subject: [PATCH 12/25] fix: allow support for multiple denoms from same zone in tvl calc --- osmosis-types/validation.go | 6 +- .../v1/participationrewards.proto | 15 +-- x/interchainstaking/keeper/hooks.go | 28 ----- x/participationrewards/genesis_test.go | 4 +- .../keeper/callbacks_test.go | 6 +- x/participationrewards/keeper/distribution.go | 79 ++++++------- .../keeper/distribution_test.go | 106 +++++++++++++++++- x/participationrewards/keeper/hooks.go | 2 +- x/participationrewards/keeper/keeper.go | 9 +- x/participationrewards/keeper/keeper_test.go | 23 ++-- .../keeper/msg_server_test.go | 68 +++++------ .../keeper/protocol_data.go | 2 +- x/participationrewards/types/errors.go | 2 + .../types/participationrewards_test.go | 8 +- .../types/protocol_data_test.go | 7 +- .../types/submodule_osmosis.go | 21 ++-- 16 files changed, 237 insertions(+), 149 deletions(-) diff --git a/osmosis-types/validation.go b/osmosis-types/validation.go index 5a3f3351b..bf3a88100 100644 --- a/osmosis-types/validation.go +++ b/osmosis-types/validation.go @@ -34,9 +34,9 @@ func DetermineApplicableTokensInPool(ctx sdk.Context, prKeeper ParticipationRewa pool, _ := ipool.(*participationrewardstypes.OsmosisPoolProtocolData) poolDenom := "" - for zk, zd := range pool.Zones { - if zk == chainID { - poolDenom = zd + for zk, zd := range pool.Denoms { + if zd.ChainId == chainID { + poolDenom = zk break } } diff --git a/proto/quicksilver/participationrewards/v1/participationrewards.proto b/proto/quicksilver/participationrewards/v1/participationrewards.proto index 9838905cf..dccffb8e0 100644 --- a/proto/quicksilver/participationrewards/v1/participationrewards.proto +++ b/proto/quicksilver/participationrewards/v1/participationrewards.proto @@ -28,16 +28,6 @@ message DistributionProportions { ]; } -// Params holds parameters for the participationrewards module. -message Params_v1 { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; - - // distribution_proportions defines the proportions of the minted - // participation rewards; - DistributionProportions distribution_proportions = 1 [(gogoproto.nullable) = false]; -} - // Params holds parameters for the participationrewards module. message Params { option (gogoproto.goproto_getters) = false; @@ -45,7 +35,8 @@ message Params { // distribution_proportions defines the proportions of the minted // participation rewards; - DistributionProportions distribution_proportions = 1 [(gogoproto.nullable) = false]; + DistributionProportions distribution_proportions = 1 + [ (gogoproto.nullable) = false ]; bool claims_enabled = 2; } @@ -58,7 +49,7 @@ message KeyedProtocolData { // determination of rewards. message ProtocolData { string type = 1; - bytes data = 2 [(gogoproto.casttype) = "encoding/json.RawMessage"]; + bytes data = 2 [ (gogoproto.casttype) = "encoding/json.RawMessage" ]; } enum ProtocolDataType { diff --git a/x/interchainstaking/keeper/hooks.go b/x/interchainstaking/keeper/hooks.go index afd15e747..c2b3db8fe 100644 --- a/x/interchainstaking/keeper/hooks.go +++ b/x/interchainstaking/keeper/hooks.go @@ -4,11 +4,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/ingenuity-build/quicksilver/utils" epochstypes "github.com/ingenuity-build/quicksilver/x/epochs/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -26,32 +24,6 @@ func (k *Keeper) BeforeEpochStart(_ sdk.Context, _ string, _ int64) error { // // and re-queries icq for new zone info. func (k *Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error { - // every day - if epochIdentifier == epochstypes.EpochIdentifierDay { - - k.Logger(ctx).Info("handling day end", "epoch_identifier", epochIdentifier, "epoch_number", epochNumber) - k.Logger(ctx).Debug("flushing outstanding delegations for the day") - k.IterateZones(ctx, func(index int64, zone *types.Zone) (stop bool) { - addressBytes, err := utils.AccAddressFromBech32(zone.DelegationAddress.Address, zone.AccountPrefix) - if err != nil { - k.Logger(ctx).Error("cannot decode bech32 delegation addr") - return false - } - - k.ICQKeeper.MakeRequest( - ctx, - zone.ConnectionId, - zone.ChainId, - types.BankStoreKey, - append(banktypes.CreateAccountBalancesPrefix(addressBytes), []byte(zone.BaseDenom)...), - sdk.NewInt(-1), - types.ModuleName, - "delegationaccountbalance", - 0, - ) - return false - }) - } // every epoch if epochIdentifier == epochstypes.EpochIdentifierEpoch { k.Logger(ctx).Info("handling epoch end", "epoch_identifier", epochIdentifier, "epoch_number", epochNumber) diff --git a/x/participationrewards/genesis_test.go b/x/participationrewards/genesis_test.go index b40a3649f..3613f4131 100644 --- a/x/participationrewards/genesis_test.go +++ b/x/participationrewards/genesis_test.go @@ -56,8 +56,8 @@ func TestParticipationRewardsInitGenesis(t *testing.T) { "poolid": 1, "poolname": "atom/osmo", "pooltype": "balancer", - "zones": { - "zone_id": "IBC/zone_denom" + "denoms": { + "ibc/00000000000000000000000000000000": {"denom": "ustake", "chainid": "testzone-1"} } }` diff --git a/x/participationrewards/keeper/callbacks_test.go b/x/participationrewards/keeper/callbacks_test.go index 95577c23e..d400174ce 100644 --- a/x/participationrewards/keeper/callbacks_test.go +++ b/x/participationrewards/keeper/callbacks_test.go @@ -52,9 +52,9 @@ func (suite *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { LastUpdated: ctx.BlockTime(), PoolData: expectedData, PoolType: "balancer", - Zones: map[string]string{ - "cosmoshub-4": "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", - "osmosis-1": "ibc/15E9C5CF5969080539DB395FA7D9C0868265217EFC528433671AAF9B1912D159", + Denoms: map[string]types.DenomWithZone{ + "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3": {ChainId: "cosmoshub-4", Denom: "uatom"}, + "ibc/15E9C5CF5969080539DB395FA7D9C0868265217EFC528433671AAF9B1912D159": {ChainId: "osmosis-1", Denom: "uosmo"}, }, } diff --git a/x/participationrewards/keeper/distribution.go b/x/participationrewards/keeper/distribution.go index e2e94bdf0..3bb535190 100644 --- a/x/participationrewards/keeper/distribution.go +++ b/x/participationrewards/keeper/distribution.go @@ -8,21 +8,22 @@ import ( "github.com/ingenuity-build/quicksilver/internal/multierror" "github.com/ingenuity-build/quicksilver/utils" + icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -type tokenValues map[string]sdk.Dec +type TokenValues map[string]sdk.Dec -func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { +func (k *Keeper) CalcTokenValues(ctx sdk.Context) (TokenValues, error) { k.Logger(ctx).Info("calcTokenValues") data, found := k.GetProtocolData(ctx, types.ProtocolDataTypeOsmosisParams, "osmosisparams") if !found { - return tokenValues{}, errors.New("could not find osmosisparams protocol data") + return TokenValues{}, errors.New("could not find osmosisparams protocol data") } osmoParams, err := types.UnmarshalProtocolData(types.ProtocolDataTypeOsmosisParams, data.Data) if err != nil { - return tokenValues{}, err + return TokenValues{}, err } baseDenom := osmoParams.(*types.OsmosisParamsProtocolData).BaseDenom @@ -44,8 +45,8 @@ func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { } pool, _ := ipool.(*types.OsmosisPoolProtocolData) - // pool must be a cosmos pair - if len(pool.Zones) != 2 { + // pool must be a base pair + if len(pool.Denoms) != 2 { // not a pair: skip return false } @@ -57,34 +58,40 @@ func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { var baseIBCDenom, queryIBCDenom, valueDenom string isBasePair := false - for chainID, denom := range pool.Zones { - if chainID == baseChain { + for ibcDenom, denom := range pool.Denoms { + if denom.ChainId == baseChain { isBasePair = true - baseIBCDenom = denom - continue + baseIBCDenom = ibcDenom + } else { + zone, ok := k.icsKeeper.GetZone(ctx, denom.ChainId) + if !ok { + //errs[idxLabel] = fmt.Errorf("zone not found, %s", denom.ChainId) + return false + } + + if denom.Denom == zone.BaseDenom { + queryIBCDenom = ibcDenom + valueDenom = zone.BaseDenom + } else { + return false + } } - - zone, ok := k.icsKeeper.GetZone(ctx, chainID) - if !ok { - errs[idxLabel] = fmt.Errorf("zone not found, %s", chainID) - return true - } - - queryIBCDenom = denom - valueDenom = zone.BaseDenom } - if isBasePair { + if !isBasePair { + return false // baseChain does not feature here, so ignore! + } else { if pool.PoolData == nil { errs[idxLabel] = fmt.Errorf("pool data is nil, awaiting OsmosisPoolUpdateCallback") return true } - pool, err := pool.GetPool() + gammPool, err := pool.GetPool() if err != nil { errs[idxLabel] = err return true } - value, err := pool.SpotPrice(ctx, baseIBCDenom, queryIBCDenom) + + value, err := gammPool.SpotPrice(ctx, baseIBCDenom, queryIBCDenom) if err != nil { errs[idxLabel] = err return true @@ -106,7 +113,7 @@ func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { // AllocateZoneRewards executes zone based rewards allocation. This entails // rewards that are proportionally distributed to zones based on the tvl for // each zone relative to the tvl of the QS protocol. -func (k *Keeper) AllocateZoneRewards(ctx sdk.Context, tvs tokenValues, allocation types.RewardsAllocation) error { +func (k *Keeper) AllocateZoneRewards(ctx sdk.Context, tvs TokenValues, allocation types.RewardsAllocation) error { k.Logger(ctx).Info("allocateZoneRewards", "token values", tvs, "allocation", allocation) if err := k.SetZoneAllocations(ctx, tvs, allocation); err != nil { @@ -120,29 +127,27 @@ func (k *Keeper) AllocateZoneRewards(ctx sdk.Context, tvs tokenValues, allocatio // SetZoneAllocations returns the proportional zone rewards allocations as a // map indexed by the zone id. -func (k *Keeper) SetZoneAllocations(ctx sdk.Context, tvs tokenValues, allocation types.RewardsAllocation) error { +func (k *Keeper) SetZoneAllocations(ctx sdk.Context, tvs TokenValues, allocation types.RewardsAllocation) error { k.Logger(ctx).Info("setZoneAllocations", "allocation", allocation) otvl := sdk.ZeroDec() // pass 1: iterate zones - set tvl & calc overall tvl - for _, zone := range k.icsKeeper.AllZones(ctx) { - // explicit memory referencing - zone := zone + k.icsKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { tv, exists := tvs[zone.BaseDenom] if !exists { k.Logger(ctx).Error(fmt.Sprintf("unable to obtain token value for zone %s", zone.ChainId)) - continue + return false } - ztvl := sdk.NewDecFromInt(k.icsKeeper.GetDelegatedAmount(ctx, &zone).Amount.Add(k.icsKeeper.GetDelegationsInProcess(ctx, &zone))).Mul(tv) - + ztvl := sdk.NewDecFromInt(k.icsKeeper.GetDelegatedAmount(ctx, zone).Amount.Add(k.icsKeeper.GetDelegationsInProcess(ctx, zone))).Mul(tv) zone.Tvl = ztvl - k.icsKeeper.SetZone(ctx, &zone) + k.icsKeeper.SetZone(ctx, zone) k.Logger(ctx).Info("zone tvl", "zone", zone.ChainId, "tvl", ztvl) otvl = otvl.Add(ztvl) - } + return false + }) // check overall protocol tvl if otvl.IsZero() { @@ -151,9 +156,7 @@ func (k *Keeper) SetZoneAllocations(ctx sdk.Context, tvs tokenValues, allocation } // pass 2: iterate zones - calc zone tvl proportion & set allocations - for _, zone := range k.icsKeeper.AllZones(ctx) { - // explicit memory referencing - zone := zone + k.icsKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { if zone.Tvl.IsNil() { zone.Tvl = sdk.ZeroDec() @@ -164,9 +167,9 @@ func (k *Keeper) SetZoneAllocations(ctx sdk.Context, tvs tokenValues, allocation zone.ValidatorSelectionAllocation = sdk.NewDecFromInt(allocation.ValidatorSelection).Mul(zp).TruncateInt().Uint64() zone.HoldingsAllocation = sdk.NewDecFromInt(allocation.Holdings).Mul(zp).TruncateInt().Uint64() - - k.icsKeeper.SetZone(ctx, &zone) - } + k.icsKeeper.SetZone(ctx, zone) + return false + }) return nil } diff --git a/x/participationrewards/keeper/distribution_test.go b/x/participationrewards/keeper/distribution_test.go index d666193bc..fd3d99b92 100644 --- a/x/participationrewards/keeper/distribution_test.go +++ b/x/participationrewards/keeper/distribution_test.go @@ -1,5 +1,109 @@ package keeper_test -func (suite *KeeperTestSuite) SetZoneAllocationsTest() { +import ( + "encoding/json" + "time" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/ingenuity-build/quicksilver/x/participationrewards/keeper" + "github.com/ingenuity-build/quicksilver/x/participationrewards/types" +) + +func (suite *KeeperTestSuite) TestCalcTokenValues() { + type cases struct { + name string + osmosisParams types.OsmosisParamsProtocolData + osmosisPools []types.OsmosisPoolProtocolData + expectedTvs keeper.TokenValues + } + + tests := []cases{ + { + osmosisParams: types.OsmosisParamsProtocolData{ + ChainID: "osmosis-1", + BaseDenom: "uosmo", + BaseChain: "osmosis-1", + }, + osmosisPools: []types.OsmosisPoolProtocolData{ + { + PoolID: 956, + PoolName: "qOsmo/osmo", + LastUpdated: time.Now().UTC(), + PoolType: "stableswap", + PoolData: json.RawMessage("{\"address\":\"osmo1q023e9m4d3ffvr96xwaeraa62yfvufkufkr7yf7lmacgkuspsuqsga4xp2\",\"id\":956,\"pool_params\":{\"swap_fee\":\"0.003000000000000000\",\"exit_fee\":\"0.000000000000000000\"},\"future_pool_governor\":\"168h\",\"total_shares\":{\"denom\":\"gamm/pool/956\",\"amount\":\"118922578939571354422559\"},\"pool_liquidity\":[{\"denom\":\"ibc/42D24879D4569CE6477B7E88206ADBFE47C222C6CAD51A54083E4A72594269FC\",\"amount\":\"217240952822\"},{\"denom\":\"uosmo\",\"amount\":\"260096955062\"}],\"scaling_factors\":[\"1000000000\",\"1045466083\"],\"scaling_factor_controller\":\"osmo16x03wcp37kx5e8ehckjxvwcgk9j0cqnhm8m3yy\"}"), + Denoms: map[string]types.DenomWithZone{}, + IsIncentivized: true, + }, + { + PoolID: 944, + PoolName: "atom/qAtom", + LastUpdated: time.Now().UTC(), + PoolType: "stableswap", + PoolData: json.RawMessage("{\"address\":\"osmo1awr39mc2hrkt8gq8gt3882ru40ay45k8a3yg69nyypqe9g0ryycs66lhkh\",\"id\":944,\"pool_params\":{\"swap_fee\":\"0.003000000000000000\",\"exit_fee\":\"0.000000000000000000\"},\"future_pool_governor\":\"168h\",\"total_shares\":{\"denom\":\"gamm/pool/944\",\"amount\":\"9298235648962291280150\"},\"pool_liquidity\":[{\"denom\":\"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2\",\"amount\":\"73166403902\"},{\"denom\":\"ibc/FA602364BEC305A696CBDF987058E99D8B479F0318E47314C49173E8838C5BAC\",\"amount\":\"98593533184\"}],\"scaling_factors\":[\"1071353717\",\"1000000000\"],\"scaling_factor_controller\":\"osmo16x03wcp37kx5e8ehckjxvwcgk9j0cqnhm8m3yy\"}"), + Denoms: map[string]types.DenomWithZone{}, + IsIncentivized: true, + }, + { + PoolID: 1, + PoolName: "Atom/Osmo", + LastUpdated: time.Now().UTC(), + PoolType: "balancer", + PoolData: json.RawMessage("{\"address\":\"osmo1mw0ac6rwlp5r8wapwk3zs6g29h8fcscxqakdzw9emkne6c8wjp9q0t3v8t\",\"id\":1,\"pool_params\":{\"swap_fee\":\"0.002000000000000000\",\"exit_fee\":\"0.000000000000000000\",\"smooth_weight_change_params\":null},\"future_pool_governor\":\"24h\",\"total_shares\":{\"denom\":\"gamm/pool/1\",\"amount\":\"216987393856026889179749817\"},\"pool_assets\":[{\"token\":{\"denom\":\"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2\",\"amount\":\"1909639500022\"},\"weight\":\"536870912000000\"},{\"token\":{\"denom\":\"uosmo\",\"amount\":\"35673230362499\"},\"weight\":\"536870912000000\"}],\"total_weight\":\"1073741824000000\"}"), + Denoms: map[string]types.DenomWithZone{ + "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {Denom: "uatom", ChainId: "cosmoshub-4"}, + "uosmo": {Denom: "uosmo", ChainId: "osmosis-1"}, + }, + IsIncentivized: false, + }, + { + PoolID: 952, + PoolName: "qck/osmo", + LastUpdated: time.Now().UTC(), + PoolType: "balancer", + PoolData: json.RawMessage("{\"address\":\"osmo1k3j5wgcj8um2gnu8qxdm0mzzuh6x66p4p7gn6fraf3wnpfcvg9sq2zhx7j\",\"id\":\"952\",\"pool_params\":{\"swap_fee\":\"0.003000000000000000\",\"exit_fee\":\"0.000000000000000000\",\"smooth_weight_change_params\":null},\"future_pool_governor\":\"168h\",\"total_shares\":{\"denom\":\"gamm/pool/952\",\"amount\":\"281109110456689694028077\"},\"pool_assets\":[{\"token\":{\"denom\":\"ibc/635CB83EF1DFE598B10A3E90485306FD0D47D34217A4BE5FD9977FA010A5367D\",\"amount\":\"1036526700301\"},\"weight\":\"1073741824\"},{\"token\":{\"denom\":\"uosmo\",\"amount\":\"162265452817\"},\"weight\":\"1073741824\"}],\"total_weight\":\"2147483648\"}"), + Denoms: map[string]types.DenomWithZone{ + "ibc/635CB83EF1DFE598B10A3E90485306FD0D47D34217A4BE5FD9977FA010A5367D": {Denom: "uqck", ChainId: "quicksilver-2"}, + "uosmo": {Denom: "uosmo", ChainId: "osmosis-1"}, + }, + IsIncentivized: false, + }, + }, + expectedTvs: keeper.TokenValues{ + "uatom": sdk.MustNewDecFromStr("18.680609802053228677"), + "uosmo": sdk.MustNewDecFromStr("1.000000000000000000"), + }, + }, + } + + for _, tt := range tests { + tt := tt + + suite.Run(tt.name, func() { + suite.SetupTest() + + qs := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() + osmoParamsJson, err := json.Marshal(tt.osmosisParams) + suite.Require().NoError(err) + data := types.ProtocolData{ + Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisParams)], + Data: osmoParamsJson, + } + qs.ParticipationRewardsKeeper.SetProtocolData(ctx, tt.osmosisParams.GenerateKey(), &data) + + for _, pool := range tt.osmosisPools { + poolJson, err := json.Marshal(pool) + suite.Require().NoError(err) + data := types.ProtocolData{ + Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisPool)], + Data: poolJson, + } + qs.ParticipationRewardsKeeper.SetProtocolData(ctx, pool.GenerateKey(), &data) + } + tvs, err := qs.ParticipationRewardsKeeper.CalcTokenValues(ctx) + suite.Require().NoError(err) + suite.Require().Equal(tt.expectedTvs, tvs) + }) + } } diff --git a/x/participationrewards/keeper/hooks.go b/x/participationrewards/keeper/hooks.go index 200e496c4..300c21755 100644 --- a/x/participationrewards/keeper/hooks.go +++ b/x/participationrewards/keeper/hooks.go @@ -62,7 +62,7 @@ func (k *Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, _ int64) sub.Hooks(ctx, k) } - tvs, err := k.calcTokenValues(ctx) + tvs, err := k.CalcTokenValues(ctx) if err != nil { k.Logger(ctx).Error("unable to calculate token values", "error", err.Error()) return nil diff --git a/x/participationrewards/keeper/keeper.go b/x/participationrewards/keeper/keeper.go index e8f32446a..9d0ed4293 100644 --- a/x/participationrewards/keeper/keeper.go +++ b/x/participationrewards/keeper/keeper.go @@ -118,12 +118,13 @@ func (k *Keeper) GetCodec() codec.BinaryCodec { } func (k *Keeper) UpdateSelfConnectionData(ctx sdk.Context) error { - selfConnectionData, err := json.Marshal(types.ConnectionProtocolData{ + selfConnectionData := types.ConnectionProtocolData{ ConnectionID: types.SelfConnection, ChainID: ctx.ChainID(), LastEpoch: ctx.BlockHeight() - 2, // reason why -2 works here. Prefix: config.Bech32Prefix, - }) + } + selfConnectionDataBlob, err := json.Marshal(selfConnectionData) if err != nil { k.Logger(ctx).Info("Error Marshalling self connection Data") return err @@ -131,10 +132,10 @@ func (k *Keeper) UpdateSelfConnectionData(ctx sdk.Context) error { data := types.ProtocolData{ Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeConnection)], - Data: selfConnectionData, + Data: selfConnectionDataBlob, } k.Logger(ctx).Info("Setting self protocol data", "data", data) - k.SetProtocolData(ctx, []byte(ctx.ChainID()), &data) + k.SetProtocolData(ctx, selfConnectionData.GenerateKey(), &data) return nil } diff --git a/x/participationrewards/keeper/keeper_test.go b/x/participationrewards/keeper/keeper_test.go index 30eb597ac..85aa8684c 100644 --- a/x/participationrewards/keeper/keeper_test.go +++ b/x/participationrewards/keeper/keeper_test.go @@ -371,15 +371,18 @@ func (suite *KeeperTestSuite) setupTestProtocolData() { suite.addProtocolData( types.ProtocolDataTypeOsmosisPool, []byte(fmt.Sprintf( - "{\"poolid\":%d,\"poolname\":%q,\"pooltype\":\"balancer\",\"zones\":{%q:%q,%q:%q}}", + "{\"poolid\":%d,\"poolname\":%q,\"pooltype\":\"balancer\",\"denoms\":{%q:{\"chainid\": %q, \"denom\":%q}, %q:{\"chainid\": %q, \"denom\":%q}}}", 1, "atom/osmo", - "cosmoshub-4", "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", - "osmosis-1", + "cosmoshub-4", + "uatom", "ibc/15E9C5CF5969080539DB395FA7D9C0868265217EFC528433671AAF9B1912D159", + "osmosis-1", + "uosmo", )), ) + // atom (cosmoshub) on osmosis suite.addProtocolData( types.ProtocolDataTypeLiquidToken, @@ -408,7 +411,7 @@ func (suite *KeeperTestSuite) addProtocolData(dataType types.ProtocolDataType, d pd := types.ProtocolData{ Type: types.ProtocolDataType_name[int32(dataType)], - Data: []byte(data), + Data: data, } upd, err := types.UnmarshalProtocolData(dataType, pd.Data) @@ -457,11 +460,15 @@ func (suite *KeeperTestSuite) setupTestDeposits() { } func (suite *KeeperTestSuite) addReceipt(zone *icstypes.Zone, sender, hash string, coins sdk.Coins) { + t := time.Now().Add(-time.Hour) + t2 := time.Now().Add(-5 * time.Minute) receipt := icstypes.Receipt{ - ChainId: zone.ChainId, - Sender: sender, - Txhash: hash, - Amount: coins, + ChainId: zone.ChainId, + Sender: sender, + Txhash: hash, + Amount: coins, + FirstSeen: &t, + Completed: &t2, } suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetReceipt(suite.chainA.GetContext(), receipt) diff --git a/x/participationrewards/keeper/msg_server_test.go b/x/participationrewards/keeper/msg_server_test.go index 54e0ebfa7..5df1a15f4 100644 --- a/x/participationrewards/keeper/msg_server_test.go +++ b/x/participationrewards/keeper/msg_server_test.go @@ -267,7 +267,7 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { } } -func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { +func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { address := utils.GenerateAccAddressForTest() var msg *types.MsgSubmitClaim @@ -297,8 +297,8 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: suite.chainB.ChainID, - SrcZone: suite.chainA.ChainID, + Zone: s.chainB.ChainID, + SrcZone: s.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -318,8 +318,8 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { { "local_callback_value_invalid_denom", func(ctx sdk.Context, appA *app.Quicksilver) { - suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) - suite.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + s.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) }, func(ctx sdk.Context, appA *app.Quicksilver) *types.MsgSubmitClaim { key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("uqatom")) @@ -335,8 +335,8 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: suite.chainB.ChainID, - SrcZone: suite.chainA.ChainID, + Zone: s.chainB.ChainID, + SrcZone: s.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -356,19 +356,19 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { { "local_callback_value_valid_denom", func(ctx sdk.Context, appA *app.Quicksilver) { - suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) - suite.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + s.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) // add uqatom to the list of allowed denoms for this zone rawPd := types.LiquidAllowedDenomProtocolData{ - ChainID: suite.chainA.ChainID, + ChainID: s.chainA.ChainID, IbcDenom: "uqatom", QAssetDenom: "uqatom", - RegisteredZoneChainID: suite.chainB.ChainID, + RegisteredZoneChainID: s.chainB.ChainID, } blob, err := json.Marshal(rawPd) - suite.Require().NoError(err) + s.Require().NoError(err) pd := types.NewProtocolData(types.ProtocolDataType_name[int32(types.ProtocolDataTypeLiquidToken)], blob) appA.ParticipationRewardsKeeper.SetProtocolData(ctx, rawPd.GenerateKey(), pd) @@ -387,8 +387,8 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: suite.chainB.ChainID, - SrcZone: suite.chainA.ChainID, + Zone: s.chainB.ChainID, + SrcZone: s.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -405,9 +405,9 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { "", []cmtypes.Claim{{ UserAddress: address.String(), - ChainId: suite.chainB.ChainID, + ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, - SourceChainId: suite.chainA.ChainID, + SourceChainId: s.chainA.ChainID, Amount: 100, }}, }, @@ -415,23 +415,23 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { for _, tt := range tests { tt := tt - suite.Run(tt.name, func() { - suite.SetupTest() + s.Run(tt.name, func() { + s.SetupTest() - appA := suite.GetQuicksilverApp(suite.chainA) + appA := s.GetQuicksilverApp(s.chainA) // override disabled proof verification; lets test actual proofs :) appA.ParticipationRewardsKeeper.ValidateProofOps = utils.ValidateProofOps appA.ParticipationRewardsKeeper.ValidateSelfProofOps = utils.ValidateSelfProofOps - suite.coordinator.CommitNBlocks(suite.chainA, 3) - ctx := suite.chainA.GetContext() + s.coordinator.CommitNBlocks(s.chainA, 3) + ctx := s.chainA.GetContext() tt.malleate(ctx, appA) - suite.coordinator.CommitNBlocks(suite.chainA, 3) - ctx = suite.chainA.GetContext() - suite.Require().NoError(appA.ClaimsManagerKeeper.StoreSelfConsensusState(ctx, "epoch")) - suite.coordinator.CommitNBlocks(suite.chainA, 1) + s.coordinator.CommitNBlocks(s.chainA, 3) + ctx = s.chainA.GetContext() + s.Require().NoError(appA.ClaimsManagerKeeper.StoreSelfConsensusState(ctx, "epoch")) + s.coordinator.CommitNBlocks(s.chainA, 1) - ctx = suite.chainA.GetContext() + ctx = s.chainA.GetContext() msg = tt.generate(ctx, appA) params := appA.ParticipationRewardsKeeper.GetParams(ctx) params.ClaimsEnabled = true @@ -441,22 +441,22 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { k := keeper.NewMsgServerImpl(appA.ParticipationRewardsKeeper) resp, err := k.SubmitClaim(sdk.WrapSDKContext(ctx), msg) if tt.wantErr != "" { - suite.Require().Errorf(err, tt.wantErr) - suite.Require().Nil(resp) - suite.T().Logf("Error: %v", err) + s.Require().Errorf(err, tt.wantErr) + s.Require().Nil(resp) + s.T().Logf("Error: %v", err) return } for _, expectedClaim := range tt.claims { actualClaim, found := appA.ClaimsManagerKeeper.GetClaim(ctx, expectedClaim.ChainId, expectedClaim.UserAddress, expectedClaim.Module, expectedClaim.SourceChainId) - suite.Require().True(found) - suite.Require().Equal(expectedClaim.Amount, actualClaim.Amount) + s.Require().True(found) + s.Require().Equal(expectedClaim.Amount, actualClaim.Amount) } - suite.Require().NoError(err) - suite.Require().NotNil(resp) - suite.Require().Equal(tt.want, resp) + s.Require().NoError(err) + s.Require().NotNil(resp) + s.Require().Equal(tt.want, resp) }) } } diff --git a/x/participationrewards/keeper/protocol_data.go b/x/participationrewards/keeper/protocol_data.go index c5345cfb3..3a16b44c1 100644 --- a/x/participationrewards/keeper/protocol_data.go +++ b/x/participationrewards/keeper/protocol_data.go @@ -20,7 +20,7 @@ func (k *Keeper) GetProtocolData(ctx sdk.Context, pdType types.ProtocolDataType, return data, true } -// SetProtocolData set protocol data info +// SetProtocolData set protocol data info. func (k Keeper) SetProtocolData(ctx sdk.Context, key []byte, data *types.ProtocolData) { if data == nil { k.Logger(ctx).Error("protocol data not set; value is nil") diff --git a/x/participationrewards/types/errors.go b/x/participationrewards/types/errors.go index 6cb17c846..ad03eeaeb 100644 --- a/x/participationrewards/types/errors.go +++ b/x/participationrewards/types/errors.go @@ -14,4 +14,6 @@ var ( ErrNothingToAllocate = sdkioerrors.Register(ModuleName, 9, "balance is zero, nothing to allocate") ErrInvalidAssetName = sdkioerrors.Register(ModuleName, 10, "invalid ibc asset name") ErrInvalidChainID = sdkioerrors.Register(ModuleName, 11, "invalid chain id") + ErrInvalidDenom = sdkioerrors.Register(ModuleName, 12, "invalid denom") + ErrCannotUnmarshal = sdkioerrors.Register(ModuleName, 13, "unable to unmarshal") ) diff --git a/x/participationrewards/types/participationrewards_test.go b/x/participationrewards/types/participationrewards_test.go index 97e17c59b..d93dbdc89 100644 --- a/x/participationrewards/types/participationrewards_test.go +++ b/x/participationrewards/types/participationrewards_test.go @@ -74,16 +74,14 @@ func TestDistributionProportions_ValidateBasic(t *testing.T) { func TestKeyedProtocolData_ValidateBasic(t *testing.T) { invalidOsmosisData := `{ "poolname": "osmosispools/1", - "zones": { - "": "" - } + "denoms": { } }` validOsmosisData := `{ "poolid": 1, "poolname": "atom/osmo", "pooltype": "balancer", - "zones": { - "zone_id": "IBC/zone_denom" + "denoms": { + "uosmo": {"chainid": "osmosis-1", "denom": "uosmo"} } }` validLiquidData := `{ diff --git a/x/participationrewards/types/protocol_data_test.go b/x/participationrewards/types/protocol_data_test.go index fb7956187..a11688f86 100644 --- a/x/participationrewards/types/protocol_data_test.go +++ b/x/participationrewards/types/protocol_data_test.go @@ -197,12 +197,15 @@ func TestUnmarshalProtocolData(t *testing.T) { "osmosispool_data", args{ datatype: types.ProtocolDataTypeOsmosisPool, - data: []byte(`{"poolid": 1, "poolname": "atom/osmo","zones": {"cosmoshub-4": "IBC/atom_denom", "osmosis-1": "IBC/osmo_denom"}}`), + data: []byte(`{"poolid": 1, "poolname": "atom/osmo","denoms": {"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {"denom": "uatom", "chainid": "cosmoshub-4"}, "uosmo": {"denom": "uosmo", "chainid": "osmosis-1"}}}`), }, &types.OsmosisPoolProtocolData{ PoolID: 1, PoolName: "atom/osmo", - Zones: map[string]string{"cosmoshub-4": "IBC/atom_denom", "osmosis-1": "IBC/osmo_denom"}, + Denoms: map[string]types.DenomWithZone{ + "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {Denom: "uatom", ChainId: "cosmoshub-4"}, + "uosmo": {Denom: "uosmo", ChainId: "osmosis-1"}, + }, }, false, }, diff --git a/x/participationrewards/types/submodule_osmosis.go b/x/participationrewards/types/submodule_osmosis.go index 217e4c20e..8d746fbf0 100644 --- a/x/participationrewards/types/submodule_osmosis.go +++ b/x/participationrewards/types/submodule_osmosis.go @@ -3,8 +3,10 @@ package types import ( "encoding/json" "fmt" + "strings" "time" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ingenuity-build/quicksilver/internal/multierror" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/balancer" @@ -24,10 +26,15 @@ type OsmosisPoolProtocolData struct { LastUpdated time.Time PoolData json.RawMessage PoolType string - Zones map[string]string // chainID: IBC/denom + Denoms map[string]DenomWithZone IsIncentivized bool } +type DenomWithZone struct { + Denom string + ChainId string +} + func (opd *OsmosisPoolProtocolData) GetPool() (gamm.PoolI, error) { switch opd.PoolType { case PoolTypeBalancer: @@ -82,15 +89,15 @@ func (opd *OsmosisPoolProtocolData) ValidateBasic() error { } i := 0 - for chainID, denom := range opd.Zones { - el := fmt.Sprintf("Zones[%d]", i) + for ibcdenom, denom := range opd.Denoms { + el := fmt.Sprintf("Denoms[%s]", ibcdenom) - if chainID == "" { - errs[el+" key"] = fmt.Errorf("%w, chainID", ErrUndefinedAttribute) + if denom.ChainId == "" || len(strings.Split(denom.ChainId, "-")) < 2 { + errs[el+" key"] = fmt.Errorf("%w, chainID", ErrInvalidChainID) } - if denom == "" { - errs[el+" value"] = fmt.Errorf("%w, IBC/denom", ErrUndefinedAttribute) + if denom.Denom == "" || sdk.ValidateDenom(denom.Denom) != nil { + errs[el+" value"] = fmt.Errorf("%w, IBC/denom", ErrInvalidDenom) } i++ From 43f0dcf74b7d726de44a94a5d1e7e68b8cc87377 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Tue, 6 Jun 2023 00:38:59 +0100 Subject: [PATCH 13/25] lint --- osmosis-types/validation.go | 2 +- .../keeper/callbacks_test.go | 4 +- x/participationrewards/keeper/distribution.go | 12 ++-- .../keeper/distribution_test.go | 16 ++--- .../keeper/msg_server_test.go | 68 +++++++++---------- .../types/protocol_data_test.go | 4 +- .../types/submodule_osmosis.go | 4 +- 7 files changed, 53 insertions(+), 57 deletions(-) diff --git a/osmosis-types/validation.go b/osmosis-types/validation.go index bf3a88100..c5110e7d7 100644 --- a/osmosis-types/validation.go +++ b/osmosis-types/validation.go @@ -35,7 +35,7 @@ func DetermineApplicableTokensInPool(ctx sdk.Context, prKeeper ParticipationRewa poolDenom := "" for zk, zd := range pool.Denoms { - if zd.ChainId == chainID { + if zd.ChainID == chainID { poolDenom = zk break } diff --git a/x/participationrewards/keeper/callbacks_test.go b/x/participationrewards/keeper/callbacks_test.go index d400174ce..6b42ee1a7 100644 --- a/x/participationrewards/keeper/callbacks_test.go +++ b/x/participationrewards/keeper/callbacks_test.go @@ -53,8 +53,8 @@ func (suite *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { PoolData: expectedData, PoolType: "balancer", Denoms: map[string]types.DenomWithZone{ - "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3": {ChainId: "cosmoshub-4", Denom: "uatom"}, - "ibc/15E9C5CF5969080539DB395FA7D9C0868265217EFC528433671AAF9B1912D159": {ChainId: "osmosis-1", Denom: "uosmo"}, + "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3": {ChainID: "cosmoshub-4", Denom: "uatom"}, + "ibc/15E9C5CF5969080539DB395FA7D9C0868265217EFC528433671AAF9B1912D159": {ChainID: "osmosis-1", Denom: "uosmo"}, }, } diff --git a/x/participationrewards/keeper/distribution.go b/x/participationrewards/keeper/distribution.go index 3bb535190..1ec386d14 100644 --- a/x/participationrewards/keeper/distribution.go +++ b/x/participationrewards/keeper/distribution.go @@ -59,13 +59,13 @@ func (k *Keeper) CalcTokenValues(ctx sdk.Context) (TokenValues, error) { isBasePair := false for ibcDenom, denom := range pool.Denoms { - if denom.ChainId == baseChain { + if denom.ChainID == baseChain { isBasePair = true baseIBCDenom = ibcDenom } else { - zone, ok := k.icsKeeper.GetZone(ctx, denom.ChainId) + zone, ok := k.icsKeeper.GetZone(ctx, denom.ChainID) if !ok { - //errs[idxLabel] = fmt.Errorf("zone not found, %s", denom.ChainId) + // errs[idxLabel] = fmt.Errorf("zone not found, %s", denom.ChainId) return false } @@ -78,9 +78,7 @@ func (k *Keeper) CalcTokenValues(ctx sdk.Context) (TokenValues, error) { } } - if !isBasePair { - return false // baseChain does not feature here, so ignore! - } else { + if isBasePair { if pool.PoolData == nil { errs[idxLabel] = fmt.Errorf("pool data is nil, awaiting OsmosisPoolUpdateCallback") return true @@ -133,7 +131,6 @@ func (k *Keeper) SetZoneAllocations(ctx sdk.Context, tvs TokenValues, allocation otvl := sdk.ZeroDec() // pass 1: iterate zones - set tvl & calc overall tvl k.icsKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { - tv, exists := tvs[zone.BaseDenom] if !exists { k.Logger(ctx).Error(fmt.Sprintf("unable to obtain token value for zone %s", zone.ChainId)) @@ -157,7 +154,6 @@ func (k *Keeper) SetZoneAllocations(ctx sdk.Context, tvs TokenValues, allocation // pass 2: iterate zones - calc zone tvl proportion & set allocations k.icsKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { - if zone.Tvl.IsNil() { zone.Tvl = sdk.ZeroDec() } diff --git a/x/participationrewards/keeper/distribution_test.go b/x/participationrewards/keeper/distribution_test.go index fd3d99b92..c0af82860 100644 --- a/x/participationrewards/keeper/distribution_test.go +++ b/x/participationrewards/keeper/distribution_test.go @@ -51,8 +51,8 @@ func (suite *KeeperTestSuite) TestCalcTokenValues() { PoolType: "balancer", PoolData: json.RawMessage("{\"address\":\"osmo1mw0ac6rwlp5r8wapwk3zs6g29h8fcscxqakdzw9emkne6c8wjp9q0t3v8t\",\"id\":1,\"pool_params\":{\"swap_fee\":\"0.002000000000000000\",\"exit_fee\":\"0.000000000000000000\",\"smooth_weight_change_params\":null},\"future_pool_governor\":\"24h\",\"total_shares\":{\"denom\":\"gamm/pool/1\",\"amount\":\"216987393856026889179749817\"},\"pool_assets\":[{\"token\":{\"denom\":\"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2\",\"amount\":\"1909639500022\"},\"weight\":\"536870912000000\"},{\"token\":{\"denom\":\"uosmo\",\"amount\":\"35673230362499\"},\"weight\":\"536870912000000\"}],\"total_weight\":\"1073741824000000\"}"), Denoms: map[string]types.DenomWithZone{ - "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {Denom: "uatom", ChainId: "cosmoshub-4"}, - "uosmo": {Denom: "uosmo", ChainId: "osmosis-1"}, + "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {Denom: "uatom", ChainID: "cosmoshub-4"}, + "uosmo": {Denom: "uosmo", ChainID: "osmosis-1"}, }, IsIncentivized: false, }, @@ -63,8 +63,8 @@ func (suite *KeeperTestSuite) TestCalcTokenValues() { PoolType: "balancer", PoolData: json.RawMessage("{\"address\":\"osmo1k3j5wgcj8um2gnu8qxdm0mzzuh6x66p4p7gn6fraf3wnpfcvg9sq2zhx7j\",\"id\":\"952\",\"pool_params\":{\"swap_fee\":\"0.003000000000000000\",\"exit_fee\":\"0.000000000000000000\",\"smooth_weight_change_params\":null},\"future_pool_governor\":\"168h\",\"total_shares\":{\"denom\":\"gamm/pool/952\",\"amount\":\"281109110456689694028077\"},\"pool_assets\":[{\"token\":{\"denom\":\"ibc/635CB83EF1DFE598B10A3E90485306FD0D47D34217A4BE5FD9977FA010A5367D\",\"amount\":\"1036526700301\"},\"weight\":\"1073741824\"},{\"token\":{\"denom\":\"uosmo\",\"amount\":\"162265452817\"},\"weight\":\"1073741824\"}],\"total_weight\":\"2147483648\"}"), Denoms: map[string]types.DenomWithZone{ - "ibc/635CB83EF1DFE598B10A3E90485306FD0D47D34217A4BE5FD9977FA010A5367D": {Denom: "uqck", ChainId: "quicksilver-2"}, - "uosmo": {Denom: "uosmo", ChainId: "osmosis-1"}, + "ibc/635CB83EF1DFE598B10A3E90485306FD0D47D34217A4BE5FD9977FA010A5367D": {Denom: "uqck", ChainID: "quicksilver-2"}, + "uosmo": {Denom: "uosmo", ChainID: "osmosis-1"}, }, IsIncentivized: false, }, @@ -84,20 +84,20 @@ func (suite *KeeperTestSuite) TestCalcTokenValues() { qs := suite.GetQuicksilverApp(suite.chainA) ctx := suite.chainA.GetContext() - osmoParamsJson, err := json.Marshal(tt.osmosisParams) + osmoParamsJSON, err := json.Marshal(tt.osmosisParams) suite.Require().NoError(err) data := types.ProtocolData{ Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisParams)], - Data: osmoParamsJson, + Data: osmoParamsJSON, } qs.ParticipationRewardsKeeper.SetProtocolData(ctx, tt.osmosisParams.GenerateKey(), &data) for _, pool := range tt.osmosisPools { - poolJson, err := json.Marshal(pool) + poolJSON, err := json.Marshal(pool) suite.Require().NoError(err) data := types.ProtocolData{ Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisPool)], - Data: poolJson, + Data: poolJSON, } qs.ParticipationRewardsKeeper.SetProtocolData(ctx, pool.GenerateKey(), &data) } diff --git a/x/participationrewards/keeper/msg_server_test.go b/x/participationrewards/keeper/msg_server_test.go index 5df1a15f4..54e0ebfa7 100644 --- a/x/participationrewards/keeper/msg_server_test.go +++ b/x/participationrewards/keeper/msg_server_test.go @@ -267,7 +267,7 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { } } -func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { +func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { address := utils.GenerateAccAddressForTest() var msg *types.MsgSubmitClaim @@ -297,8 +297,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainA.ChainID, + Zone: suite.chainB.ChainID, + SrcZone: suite.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -318,8 +318,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { { "local_callback_value_invalid_denom", func(ctx sdk.Context, appA *app.Quicksilver) { - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) - s.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) }, func(ctx sdk.Context, appA *app.Quicksilver) *types.MsgSubmitClaim { key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("uqatom")) @@ -335,8 +335,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainA.ChainID, + Zone: suite.chainB.ChainID, + SrcZone: suite.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -356,19 +356,19 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { { "local_callback_value_valid_denom", func(ctx sdk.Context, appA *app.Quicksilver) { - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) - s.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) // add uqatom to the list of allowed denoms for this zone rawPd := types.LiquidAllowedDenomProtocolData{ - ChainID: s.chainA.ChainID, + ChainID: suite.chainA.ChainID, IbcDenom: "uqatom", QAssetDenom: "uqatom", - RegisteredZoneChainID: s.chainB.ChainID, + RegisteredZoneChainID: suite.chainB.ChainID, } blob, err := json.Marshal(rawPd) - s.Require().NoError(err) + suite.Require().NoError(err) pd := types.NewProtocolData(types.ProtocolDataType_name[int32(types.ProtocolDataTypeLiquidToken)], blob) appA.ParticipationRewardsKeeper.SetProtocolData(ctx, rawPd.GenerateKey(), pd) @@ -387,8 +387,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainA.ChainID, + Zone: suite.chainB.ChainID, + SrcZone: suite.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -405,9 +405,9 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { "", []cmtypes.Claim{{ UserAddress: address.String(), - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, - SourceChainId: s.chainA.ChainID, + SourceChainId: suite.chainA.ChainID, Amount: 100, }}, }, @@ -415,23 +415,23 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { for _, tt := range tests { tt := tt - s.Run(tt.name, func() { - s.SetupTest() + suite.Run(tt.name, func() { + suite.SetupTest() - appA := s.GetQuicksilverApp(s.chainA) + appA := suite.GetQuicksilverApp(suite.chainA) // override disabled proof verification; lets test actual proofs :) appA.ParticipationRewardsKeeper.ValidateProofOps = utils.ValidateProofOps appA.ParticipationRewardsKeeper.ValidateSelfProofOps = utils.ValidateSelfProofOps - s.coordinator.CommitNBlocks(s.chainA, 3) - ctx := s.chainA.GetContext() + suite.coordinator.CommitNBlocks(suite.chainA, 3) + ctx := suite.chainA.GetContext() tt.malleate(ctx, appA) - s.coordinator.CommitNBlocks(s.chainA, 3) - ctx = s.chainA.GetContext() - s.Require().NoError(appA.ClaimsManagerKeeper.StoreSelfConsensusState(ctx, "epoch")) - s.coordinator.CommitNBlocks(s.chainA, 1) + suite.coordinator.CommitNBlocks(suite.chainA, 3) + ctx = suite.chainA.GetContext() + suite.Require().NoError(appA.ClaimsManagerKeeper.StoreSelfConsensusState(ctx, "epoch")) + suite.coordinator.CommitNBlocks(suite.chainA, 1) - ctx = s.chainA.GetContext() + ctx = suite.chainA.GetContext() msg = tt.generate(ctx, appA) params := appA.ParticipationRewardsKeeper.GetParams(ctx) params.ClaimsEnabled = true @@ -441,22 +441,22 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { k := keeper.NewMsgServerImpl(appA.ParticipationRewardsKeeper) resp, err := k.SubmitClaim(sdk.WrapSDKContext(ctx), msg) if tt.wantErr != "" { - s.Require().Errorf(err, tt.wantErr) - s.Require().Nil(resp) - s.T().Logf("Error: %v", err) + suite.Require().Errorf(err, tt.wantErr) + suite.Require().Nil(resp) + suite.T().Logf("Error: %v", err) return } for _, expectedClaim := range tt.claims { actualClaim, found := appA.ClaimsManagerKeeper.GetClaim(ctx, expectedClaim.ChainId, expectedClaim.UserAddress, expectedClaim.Module, expectedClaim.SourceChainId) - s.Require().True(found) - s.Require().Equal(expectedClaim.Amount, actualClaim.Amount) + suite.Require().True(found) + suite.Require().Equal(expectedClaim.Amount, actualClaim.Amount) } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.want, resp) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.want, resp) }) } } diff --git a/x/participationrewards/types/protocol_data_test.go b/x/participationrewards/types/protocol_data_test.go index a11688f86..f8004e6e3 100644 --- a/x/participationrewards/types/protocol_data_test.go +++ b/x/participationrewards/types/protocol_data_test.go @@ -203,8 +203,8 @@ func TestUnmarshalProtocolData(t *testing.T) { PoolID: 1, PoolName: "atom/osmo", Denoms: map[string]types.DenomWithZone{ - "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {Denom: "uatom", ChainId: "cosmoshub-4"}, - "uosmo": {Denom: "uosmo", ChainId: "osmosis-1"}, + "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {Denom: "uatom", ChainID: "cosmoshub-4"}, + "uosmo": {Denom: "uosmo", ChainID: "osmosis-1"}, }, }, false, diff --git a/x/participationrewards/types/submodule_osmosis.go b/x/participationrewards/types/submodule_osmosis.go index 8d746fbf0..be379b9bd 100644 --- a/x/participationrewards/types/submodule_osmosis.go +++ b/x/participationrewards/types/submodule_osmosis.go @@ -32,7 +32,7 @@ type OsmosisPoolProtocolData struct { type DenomWithZone struct { Denom string - ChainId string + ChainID string } func (opd *OsmosisPoolProtocolData) GetPool() (gamm.PoolI, error) { @@ -92,7 +92,7 @@ func (opd *OsmosisPoolProtocolData) ValidateBasic() error { for ibcdenom, denom := range opd.Denoms { el := fmt.Sprintf("Denoms[%s]", ibcdenom) - if denom.ChainId == "" || len(strings.Split(denom.ChainId, "-")) < 2 { + if denom.ChainID == "" || len(strings.Split(denom.ChainID, "-")) < 2 { errs[el+" key"] = fmt.Errorf("%w, chainID", ErrInvalidChainID) } From 48ef8ccd72c6d005ae7f0de954fd29451c10083b Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Thu, 8 Jun 2023 01:32:28 +0100 Subject: [PATCH 14/25] fix: refactor utils/address.go to avoid import cycle when using in osmosis-types --- app/upgrades/upgrades.go | 4 +- app/upgrades_test.go | 24 +-- .../gamm/pool-models/balancer/pool.go | 5 +- utils/address.go | 107 ---------- utils/addressutils/address.go | 110 ++++++++++ utils/addressutils/address_test.go | 195 ++++++++++++++++++ utils/coins_test.go | 9 +- utils/{test.go => randomutils/random.go} | 2 +- x/airdrop/keeper/msg_server_test.go | 6 +- x/airdrop/keeper/proposal_handler_test.go | 4 +- x/airdrop/types/msgs_test.go | 6 +- x/claimsmanager/keeper/claims_test.go | 6 +- x/claimsmanager/keeper/keeper_test.go | 4 +- x/claimsmanager/types/claimsmanager_test.go | 10 +- x/claimsmanager/types/codec.go | 2 + x/claimsmanager/types/genesis_test.go | 6 +- x/claimsmanager/types/keys_test.go | 6 +- x/interchainquery/types/msgs_test.go | 4 +- x/interchainstaking/keeper/callbacks.go | 12 +- x/interchainstaking/keeper/callbacks_test.go | 31 +-- x/interchainstaking/keeper/delegation_test.go | 22 +- x/interchainstaking/keeper/fuzz_test.go | 4 +- .../keeper/ibc_packet_handlers.go | 11 +- .../keeper/ibc_packet_handlers_test.go | 157 +++++++------- x/interchainstaking/keeper/intent.go | 4 +- x/interchainstaking/keeper/intent_test.go | 6 +- x/interchainstaking/keeper/keeper.go | 7 +- x/interchainstaking/keeper/keeper_test.go | 44 ++-- x/interchainstaking/keeper/msg_server.go | 4 +- x/interchainstaking/keeper/msg_server_test.go | 31 ++- x/interchainstaking/keeper/receipt.go | 3 +- x/interchainstaking/keeper/receipt_test.go | 43 ++-- .../keeper/redelegation_record_test.go | 6 +- x/interchainstaking/keeper/validator_test.go | 6 +- x/interchainstaking/keeper/zones_test.go | 4 +- x/interchainstaking/types/accounts.go | 7 +- x/interchainstaking/types/delegation_test.go | 24 +-- x/interchainstaking/types/msgs_test.go | 22 +- x/interchainstaking/types/validator_test.go | 22 +- x/interchainstaking/types/zones.go | 4 +- x/interchainstaking/types/zones_test.go | 18 +- x/participationrewards/keeper/distribution.go | 4 +- x/participationrewards/keeper/keeper_test.go | 26 +-- .../keeper/msg_server_test.go | 23 ++- .../keeper/rewards_holdings_test.go | 6 +- x/participationrewards/types/msgs_test.go | 8 +- 46 files changed, 628 insertions(+), 441 deletions(-) delete mode 100644 utils/address.go create mode 100644 utils/addressutils/address.go create mode 100644 utils/addressutils/address_test.go rename utils/{test.go => randomutils/random.go} (97%) diff --git a/app/upgrades/upgrades.go b/app/upgrades/upgrades.go index 43c03e922..6cf15ee73 100644 --- a/app/upgrades/upgrades.go +++ b/app/upgrades/upgrades.go @@ -11,7 +11,7 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/ingenuity-build/quicksilver/app/keepers" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" prtypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) @@ -90,7 +90,7 @@ func V010402rc3UpgradeHandler( appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("rege-redwood-1"))) vals := appKeepers.InterchainstakingKeeper.GetValidators(ctx, OsmosisTestnetChainID) for _, val := range vals { - valoper, _ := utils.ValAddressFromBech32(val.ValoperAddress, "osmovaloper") + valoper, _ := addressutils.ValAddressFromBech32(val.ValoperAddress, "osmovaloper") appKeepers.InterchainstakingKeeper.DeleteValidator(ctx, OsmosisTestnetChainID, valoper) } } diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 59e9b2d86..98f5c9242 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/ingenuity-build/quicksilver/app/upgrades" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" prtypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" @@ -126,7 +126,7 @@ func (s *AppTestSuite) initTestZone() { receipt := icstypes.Receipt{ ChainId: "uni-5", - Sender: utils.GenerateAccAddressForTest().String(), + Sender: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Txhash: "TestDeposit01", Amount: sdk.NewCoins( sdk.NewCoin( @@ -178,7 +178,7 @@ func (s *AppTestSuite) initTestZone() { wRecord := icstypes.WithdrawalRecord{ ChainId: "uni-5", - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ {Valoper: "junovaloper185hgkqs8q8ysnc8cvkgd8j2knnq2m0ah6ae73gntv9ampgwpmrxqlfzywn", Amount: 1000000}, {Valoper: "junovaloper1z89utvygweg5l56fsk8ak7t6hh88fd0aa9ywed", Amount: 1000000}, @@ -195,14 +195,8 @@ func (s *AppTestSuite) initTestZone() { if err != nil { return } - addr1, err := utils.AccAddressFromBech32("quick17v9kk34km3w6hdjs2sn5s5qjdu2zrm0m3rgtmq", "quick") - if err != nil { - return - } - addr2, err := utils.AccAddressFromBech32("quick16x03wcp37kx5e8ehckjxvwcgk9j0cqnhcccnty", "quick") - if err != nil { - return - } + addr1 := addressutils.GenerateAccAddressForTest() + addr2 := addressutils.GenerateAccAddressForTest() err = s.GetQuicksilverApp(s.chainA).BankKeeper.SendCoinsFromModuleToAccount(s.chainA.GetContext(), tokenfactorytypes.ModuleName, addr1, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(1600000)))) if err != nil { @@ -278,22 +272,22 @@ func (s *AppTestSuite) TestV010402rc1UpgradeHandler() { app.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { if zone.ChainId == "uni-5" { s.Require().Nil(zone.Validators) - valAddrBytes, err := utils.ValAddressFromBech32("junovaloper185hgkqs8q8ysnc8cvkgd8j2knnq2m0ah6ae73gntv9ampgwpmrxqlfzywn", "junovaloper") + valAddrBytes, err := addressutils.ValAddressFromBech32("junovaloper185hgkqs8q8ysnc8cvkgd8j2knnq2m0ah6ae73gntv9ampgwpmrxqlfzywn", "junovaloper") s.Require().NoError(err) _, found := app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) s.Require().True(found) - valAddrBytes2, err := utils.ValAddressFromBech32("junovaloper1z89utvygweg5l56fsk8ak7t6hh88fd0aa9ywed", "junovaloper") + valAddrBytes2, err := addressutils.ValAddressFromBech32("junovaloper1z89utvygweg5l56fsk8ak7t6hh88fd0aa9ywed", "junovaloper") s.Require().NoError(err) _, found = app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes2) s.Require().True(found) } if zone.ChainId == "osmosis-1" { s.Require().Nil(zone.Validators) - valAddrBytes, err := utils.ValAddressFromBech32("osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc", "osmovaloper") + valAddrBytes, err := addressutils.ValAddressFromBech32("osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc", "osmovaloper") s.Require().NoError(err) _, found := app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) s.Require().True(found) - valAddrBytes2, err := utils.ValAddressFromBech32("osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk", "osmovaloper") + valAddrBytes2, err := addressutils.ValAddressFromBech32("osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk", "osmovaloper") s.Require().NoError(err) _, found = app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes2) s.Require().True(found) diff --git a/osmosis-types/gamm/pool-models/balancer/pool.go b/osmosis-types/gamm/pool-models/balancer/pool.go index 79eee1e18..9f17f8718 100644 --- a/osmosis-types/gamm/pool-models/balancer/pool.go +++ b/osmosis-types/gamm/pool-models/balancer/pool.go @@ -9,10 +9,10 @@ import ( sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/internal/cfmm_common" + "github.com/ingenuity-build/quicksilver/utils/addressutils" ) //nolint:deadcode @@ -75,11 +75,12 @@ func NewBalancerPool(poolId uint64, balancerPoolParams PoolParams, assets []Pool // GetAddress returns the address of a pool. // If the pool address is not bech32 valid, it returns an empty address. func (p Pool) GetAddress() sdk.AccAddress { - _, addr, err := bech32.DecodeAndConvert(p.Address) + addr, err := addressutils.AccAddressFromBech32(p.Address, "") if err != nil { panic(fmt.Sprintf("could not bech32 decode address of pool with id: %d", p.GetId())) } return addr + } func (p Pool) GetId() uint64 { diff --git a/utils/address.go b/utils/address.go deleted file mode 100644 index 5bc0a6c10..000000000 --- a/utils/address.go +++ /dev/null @@ -1,107 +0,0 @@ -package utils - -import ( - "crypto/rand" - "errors" - "fmt" - "strings" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" -) - -func AccAddressFromBech32(address, checkHRP string) (addr sdk.AccAddress, err error) { - if strings.TrimSpace(address) == "" { - return sdk.AccAddress{}, errors.New("empty address string is not allowed") - } - - hrp, bz, err := bech32.DecodeAndConvert(address) - if err != nil { - return nil, err - } - - if checkHRP != "" { - if checkHRP != hrp { - return sdk.AccAddress{}, fmt.Errorf("unexpected hrp - got %s expected %s", hrp, checkHRP) - } - } - - err = sdk.VerifyAddressFormat(bz) - if err != nil { - return nil, err - } - - return sdk.AccAddress(bz), nil -} - -func ValAddressFromBech32(address, checkHRP string) (addr sdk.ValAddress, err error) { - if strings.TrimSpace(address) == "" { - return sdk.ValAddress{}, errors.New("empty address string is not allowed") - } - - hrp, bz, err := bech32.DecodeAndConvert(address) - if err != nil { - return nil, err - } - - if checkHRP != "" { - if checkHRP != hrp { - return sdk.ValAddress{}, fmt.Errorf("unexpected hrp - got %s expected %s", hrp, checkHRP) - } - } - - err = sdk.VerifyAddressFormat(bz) - if err != nil { - return nil, err - } - - return sdk.ValAddress(bz), nil -} - -func GenerateAccAddressForTest() sdk.AccAddress { - size := 32 // change the length of the generated random string here - - rb := make([]byte, size) - _, err := rand.Read(rb) - if err != nil { - panic(err) - } - - return sdk.AccAddress(rb) -} - -func GenerateValAddressForTest() sdk.ValAddress { - size := 32 // change the length of the generated random string here - - rb := make([]byte, size) - _, err := rand.Read(rb) - if err != nil { - panic(err) - } - - return sdk.ValAddress(rb) -} - -func GenerateValAddressForTestWithPrefix(hrp string) string { - addr, err := bech32.ConvertAndEncode(hrp, GenerateValAddressForTest()) - if err != nil { - panic(err) - } - return addr -} - -func GenerateAccAddressForTestWithPrefix(hrp string) string { - addr, err := bech32.ConvertAndEncode(hrp, GenerateAccAddressForTest()) - if err != nil { - panic(err) - } - return addr -} - -func ConvertAccAddressForTestUsingPrefix(address sdk.AccAddress, prefix string) string { - addr, err := bech32.ConvertAndEncode(prefix, address) - if err != nil { - panic(err) - } - return addr -} diff --git a/utils/addressutils/address.go b/utils/addressutils/address.go new file mode 100644 index 000000000..59c304bd3 --- /dev/null +++ b/utils/addressutils/address.go @@ -0,0 +1,110 @@ +package addressutils + +import ( + "errors" + "fmt" + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/bech32" + "github.com/ingenuity-build/quicksilver/utils/randomutils" +) + +// AddressFromBech32 decodes a bech32 encoded address into a byte-slice, and validates the prefix (hrp). +// An empty prefix param skips the checking. +// Returns an error if address is zero-length, invalid or the prefix does not match. +func AddressFromBech32(address, prefix string) (addr []byte, err error) { + if strings.TrimSpace(address) == "" { + return nil, errors.New("empty address string is not allowed") + } + + hrp, bz, err := bech32.DecodeAndConvert(address) + if err != nil { + return nil, err + } + + if prefix != "" { + if prefix != hrp { + return nil, fmt.Errorf("unexpected prefix - got %s expected %s", hrp, prefix) + } + } + + err = sdk.VerifyAddressFormat(bz) + if err != nil { + return nil, err + } + + return bz, nil +} + +// AccAddressFromBech32 decodes a bech32 encoded address into an sdk.AccAddress, and validates the prefix (hrp). +// An empty prefix param skips the checking. +// Returns an error if address is zero-length, invalid or the prefix does not match. +func AccAddressFromBech32(address, prefix string) (sdk.AccAddress, error) { + addr, err := AddressFromBech32(address, prefix) + return sdk.AccAddress(addr), err +} + +// MustAccAddressFromBech32 decodes a bech32 encoded address into an sdk.AccAddress, and validates the prefix (hrp). +// An empty prefix param skips the checking. +// Panics if address is zero-length, invalid or the prefix does not match. +func MustAccAddressFromBech32(address, prefix string) sdk.AccAddress { + accAddress, err := AccAddressFromBech32(address, prefix) + if err != nil { + panic(err) + } + return accAddress +} + +// ValAddressFromBech32 decodes a bech32 encoded address into an sdk.ValAddress, and validates the prefix (hrp). +// An empty prefix param skips the checking. +// Returns an error if address is zero-length, invalid or the prefix does not match. +func ValAddressFromBech32(address, prefix string) (sdk.ValAddress, error) { + addr, err := AddressFromBech32(address, prefix) + return sdk.ValAddress(addr), err +} + +// MustValAddressFromBech32 decodes a bech32 encoded address into an sdk.ValAddress, and validates the prefix (hrp). +// An empty prefix param skips the checking. +// Panics if address is zero-length, invalid or the prefix does not match. +func MustValAddressFromBech32(address, prefix string) sdk.ValAddress { + valAddress, err := ValAddressFromBech32(address, prefix) + if err != nil { + panic(err) + } + return valAddress +} + +// GenerateAccAddressForTest generates a random sdk.AccAddress for test purposes. +func GenerateAccAddressForTest() sdk.AccAddress { + return sdk.AccAddress(randomutils.GenerateRandomHash()) +} + +// GenerateValAddressForTest generates a random sdk.ValAddress for test purposes. +func GenerateValAddressForTest() sdk.ValAddress { + return sdk.ValAddress(randomutils.GenerateRandomHash()) +} + +// GenerateAddressForTestWithPrefix generates a random bech32 address with the specified prefix for test purposes. +func GenerateAddressForTestWithPrefix(prefix string) string { + // AccAddress and ValAddress are simple a byte slice, so it doesn't matter this is AccAddress below. + return MustEncodeAddressToBech32(prefix, GenerateAccAddressForTest()) +} + +// EncodeAddressToBech32 encodes an sdk.Address interface with the specified prefix. +// Identical behaviour to bech32.ConvertAndDecode(); added to addressutils for consistency. +// Error is thrown if encoding fails. +func EncodeAddressToBech32(prefix string, address sdk.Address) (string, error) { + return bech32.ConvertAndEncode(prefix, address.Bytes()) +} + +// EncodeAddressToBech32 encodes an sdk.Address interface with the specified prefix. +// Identical behaviour to bech32.ConvertAndDecode(); added to addressutils for consistency. +// Panics if encoding fails. +func MustEncodeAddressToBech32(prefix string, address sdk.Address) string { + addr, err := EncodeAddressToBech32(prefix, address) + if err != nil { + panic(err) + } + return addr +} diff --git a/utils/addressutils/address_test.go b/utils/addressutils/address_test.go new file mode 100644 index 000000000..36a21a6d1 --- /dev/null +++ b/utils/addressutils/address_test.go @@ -0,0 +1,195 @@ +package addressutils_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/ingenuity-build/quicksilver/utils/addressutils" +) + +func TestAddressFromBech32(t *testing.T) { + cases := []struct { + name string + address string + prefix string + expectedBytes []byte + expectedErr string + }{ + { + "invalid - empty string", + "", + "", + nil, + "empty address string is not allowed", + }, + { + "invalid - invalid address", + "quick", + "", + nil, + "decoding bech32 failed: invalid bech32 string length 5", + }, + { + "invalid - invalid characters", + "sbg2apkjme1qh2ycto7jn30nu", + "", + nil, + "decoding bech32 failed: invalid character not part of charset: 111", + }, + { + "invalid - invalid checksum", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh28caaaaaa", + "", + nil, + "decoding bech32 failed: invalid checksum (expected 098lr8 got aaaaaa)", + }, + { + "invalid - invalid separator", + "cosmos2kv4ez0rgrd679m6da96apnqxkcamh28c098lr8", + "", + nil, + "decoding bech32 failed: invalid separator index -1", + }, + { + "invalid - invalid hrp", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh28c098lr8", + "quick", + nil, + "unexpected prefix - got cosmos expected quick", + }, + { + "invalid - no prefix", + "1kv4ez0rgrd679m6da96apnqxkcamh28c00j09s", + "quick", + nil, + "decoding bech32 failed: invalid separator index 0", + }, + { + "invalid - too long", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh0rgrd6grd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxk79m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da79m6da96apnqxkcamh28cc63a68", + "", + nil, + "decoding bech32 failed: invalid bech32 string length 4393", + }, + { + "valid - no check", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh28c098lr8", + "", + []byte{0xb3, 0x2b, 0x91, 0x3c, 0x68, 0x1b, 0x75, 0xe2, 0xef, 0x4d, 0xe9, 0x75, 0xd0, 0xcc, 0x6, 0xb6, 0x3b, 0xbb, 0xa8, 0xf8}, + "", + }, + { + "valid - with hrp check", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh28c098lr8", + "cosmos", + []byte{0xb3, 0x2b, 0x91, 0x3c, 0x68, 0x1b, 0x75, 0xe2, 0xef, 0x4d, 0xe9, 0x75, 0xd0, 0xcc, 0x6, 0xb6, 0x3b, 0xbb, 0xa8, 0xf8}, + "", + }, + } + + for _, c := range cases { + addr, err := addressutils.AccAddressFromBech32(c.address, c.prefix) + + if c.expectedErr != "" { + require.Error(t, err) + require.ErrorContains(t, err, c.expectedErr) + } else { + require.Equal(t, c.expectedBytes, addr.Bytes()) + } + + valaddr, err := addressutils.ValAddressFromBech32(c.address, c.prefix) + + if c.expectedErr != "" { + require.Error(t, err) + require.ErrorContains(t, err, c.expectedErr) + } else { + require.Equal(t, c.expectedBytes, valaddr.Bytes()) + } + + if c.expectedErr != "" { + require.Panics(t, func() { addressutils.MustAccAddressFromBech32(c.address, c.prefix) }) + require.Panics(t, func() { addressutils.MustValAddressFromBech32(c.address, c.prefix) }) + } else { + var addr sdk.AccAddress = addressutils.MustAccAddressFromBech32(c.address, c.prefix) + require.Equal(t, c.expectedBytes, addr.Bytes()) + + var valaddr sdk.ValAddress = addressutils.MustValAddressFromBech32(c.address, c.prefix) + require.Equal(t, c.expectedBytes, valaddr.Bytes()) + } + } +} + +func TestGenerateAccAddressForTest(t *testing.T) { + var address sdk.AccAddress = addressutils.GenerateAccAddressForTest() + require.Equal(t, 32, len(address.Bytes())) + err := sdk.VerifyAddressFormat(address.Bytes()) + require.NoError(t, err) +} + +func TestGenerateValAddressForTest(t *testing.T) { + var address sdk.ValAddress = addressutils.GenerateValAddressForTest() + require.Equal(t, 32, len(address.Bytes())) + err := sdk.VerifyAddressFormat(address.Bytes()) + require.NoError(t, err) +} + +func TestGenerateAddressForTestWithPrefix(t *testing.T) { + b32addr := addressutils.GenerateAddressForTestWithPrefix("cosmos") + _, err := addressutils.AddressFromBech32(b32addr, "cosmos") + require.NoError(t, err) +} + +func TestEncodeAddressToBech32(t *testing.T) { + + cases := []struct { + name string + addrBytes []byte + prefix string + expectedAddress string + expectedErr string + }{ + { + "valid", + []byte{0xb3, 0x2b, 0x91, 0x3c, 0x68, 0x1b, 0x75, 0xe2, 0xef, 0x4d, 0xe9, 0x75, 0xd0, 0xcc, 0x6, 0xb6, 0x3b, 0xbb, 0xa8, 0xf8}, + "cosmos", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh28c098lr8", + "", + }, + { + "surprisingly valid, single null byte", + []byte{0x00}, + "cosmos", + "cosmos1qqxuevtt", + "", + }, + { + "suprisingly valid, nil", + nil, + "cosmos", + "cosmos1550dq7", + "", + }, + { + "even more suprisingly valid - no hrp :/", + []byte{0xb3, 0x2b, 0x91, 0x3c, 0x68, 0x1b, 0x75, 0xe2, 0xef, 0x4d, 0xe9, 0x75, 0xd0, 0xcc, 0x6, 0xb6, 0x3b, 0xbb, 0xa8, 0xf8}, + "", + "1kv4ez0rgrd679m6da96apnqxkcamh28cjkahle", + "", + }, + } + + for _, c := range cases { + addr, err := addressutils.EncodeAddressToBech32(c.prefix, sdk.AccAddress(c.addrBytes)) + + if c.expectedErr != "" { + require.Error(t, err) + require.ErrorContains(t, err, c.expectedErr) + + require.Panics(t, func() { addressutils.MustEncodeAddressToBech32(c.prefix, sdk.AccAddress(c.addrBytes)) }) + } else { + require.Equal(t, c.expectedAddress, addr) + } + } +} diff --git a/utils/coins_test.go b/utils/coins_test.go index 28ab25530..3858e93e6 100644 --- a/utils/coins_test.go +++ b/utils/coins_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" utils "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" ) const expectedDenom = "denom" @@ -21,7 +22,7 @@ func TestDenomFromRequestKey(t *testing.T) { { "valid", func() (sdk.AccAddress, []byte) { - accAddr := utils.GenerateAccAddressForTest() + accAddr := addressutils.GenerateAccAddressForTest() key := banktypes.CreateAccountBalancesPrefix(accAddr.Bytes()) key = append(key, []byte(expectedDenom)...) return accAddr, key @@ -31,9 +32,9 @@ func TestDenomFromRequestKey(t *testing.T) { { "invalid - address mismatch", func() (sdk.AccAddress, []byte) { - keyAddr, err := utils.AccAddressFromBech32("cosmos135rd8ft0dyq8fv3w3hhmaa55qu3pe668j99qh67mg747ew4ad03qsgq8vh", "cosmos") + keyAddr, err := addressutils.AccAddressFromBech32("cosmos135rd8ft0dyq8fv3w3hhmaa55qu3pe668j99qh67mg747ew4ad03qsgq8vh", "cosmos") require.NoError(t, err) - checkAddr, err := utils.AccAddressFromBech32("cosmos1ent5eg0xn3pskf3fhdw8mky88ry7t4kx628ru3pzp4nqjp6eufusphlldy", "cosmos") + checkAddr, err := addressutils.AccAddressFromBech32("cosmos1ent5eg0xn3pskf3fhdw8mky88ry7t4kx628ru3pzp4nqjp6eufusphlldy", "cosmos") require.NoError(t, err) key := banktypes.CreateAccountBalancesPrefix(keyAddr.Bytes()) key = append(key, []byte(expectedDenom)...) @@ -54,7 +55,7 @@ func TestDenomFromRequestKey(t *testing.T) { { "invalid - empty denom", func() (sdk.AccAddress, []byte) { - accAddr := utils.GenerateAccAddressForTest() + accAddr := addressutils.GenerateAccAddressForTest() key := banktypes.CreateAccountBalancesPrefix(accAddr.Bytes()) key = append(key, []byte("")...) return accAddr, key diff --git a/utils/test.go b/utils/randomutils/random.go similarity index 97% rename from utils/test.go rename to utils/randomutils/random.go index e199a5d0a..8703b68ea 100644 --- a/utils/test.go +++ b/utils/randomutils/random.go @@ -1,4 +1,4 @@ -package utils +package randomutils import ( "crypto/rand" diff --git a/x/airdrop/keeper/msg_server_test.go b/x/airdrop/keeper/msg_server_test.go index ef6dad7ea..3c8918cd5 100644 --- a/x/airdrop/keeper/msg_server_test.go +++ b/x/airdrop/keeper/msg_server_test.go @@ -8,7 +8,7 @@ import ( minttypes "github.com/ingenuity-build/quicksilver/x/mint/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/airdrop/keeper" "github.com/ingenuity-build/quicksilver/x/airdrop/types" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" @@ -18,7 +18,7 @@ import ( func (s *KeeperTestSuite) Test_msgServer_Claim() { appA := s.GetQuicksilverApp(s.chainA) - userAddress := utils.GenerateAccAddressForTest().String() + userAddress := addressutils.GenerateAccAddressForTest().String() denom := "uatom" // same as test zone setup in keeper_test msg := types.MsgClaim{} @@ -492,7 +492,7 @@ func (s *KeeperTestSuite) Test_msgServer_IncentivePoolSpend() { appA := s.GetQuicksilverApp(s.chainA) modAccAddr := "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" - userAddress := utils.GenerateAccAddressForTest().String() + userAddress := addressutils.GenerateAccAddressForTest().String() denom := "uatom" // same as test zone setup in keeper_test coins := sdk.NewCoins(sdk.NewCoin(denom, sdk.NewIntFromUint64(1000))) mintCoins := sdk.NewCoins(sdk.NewCoin(denom, sdk.NewIntFromUint64(100000000))) diff --git a/x/airdrop/keeper/proposal_handler_test.go b/x/airdrop/keeper/proposal_handler_test.go index 8f621b24f..fd67cb379 100644 --- a/x/airdrop/keeper/proposal_handler_test.go +++ b/x/airdrop/keeper/proposal_handler_test.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/airdrop/keeper" "github.com/ingenuity-build/quicksilver/x/airdrop/types" ) @@ -35,7 +35,7 @@ func (s *KeeperTestSuite) TestHandleRegisterZoneDropProposal() { IsConcluded: false, } userAddresses := []string{ - utils.GenerateAccAddressForTest().String(), + addressutils.GenerateAccAddressForTest().String(), } prop := types.RegisterZoneDropProposal{} diff --git a/x/airdrop/types/msgs_test.go b/x/airdrop/types/msgs_test.go index 77c7ad289..e9bb4b02e 100644 --- a/x/airdrop/types/msgs_test.go +++ b/x/airdrop/types/msgs_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/proto/tendermint/crypto" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/airdrop/types" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) @@ -219,8 +219,8 @@ func TestMsgIncentivePoolSpendValidateBasic(t *testing.T) { } validTestCoins := sdk.NewCoins(sdk.NewCoin("test", sdk.NewIntFromUint64(10000))) - addr1 := utils.GenerateAccAddressForTest().String() - addr2 := utils.GenerateAccAddressForTest().String() + addr1 := addressutils.GenerateAccAddressForTest().String() + addr2 := addressutils.GenerateAccAddressForTest().String() tests := []struct { name string diff --git a/x/claimsmanager/keeper/claims_test.go b/x/claimsmanager/keeper/claims_test.go index 4dc403524..a343342f1 100644 --- a/x/claimsmanager/keeper/claims_test.go +++ b/x/claimsmanager/keeper/claims_test.go @@ -1,7 +1,7 @@ package keeper_test import ( - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) @@ -24,7 +24,7 @@ var testClaims = []types.Claim{ }, // random user claim on chainB (using osmosis pool) { - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), // ChainID: suite.chainB.ChainID, Module: types.ClaimTypeOsmosisPool, SourceChainId: "osmosis-1", @@ -48,7 +48,7 @@ var testClaims = []types.Claim{ }, // random user claim on "cosmoshub-4" (liquid) { - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainId: "cosmoshub-4", Module: types.ClaimTypeLiquidToken, SourceChainId: "", diff --git a/x/claimsmanager/keeper/keeper_test.go b/x/claimsmanager/keeper/keeper_test.go index 05d531da6..e955a82f0 100644 --- a/x/claimsmanager/keeper/keeper_test.go +++ b/x/claimsmanager/keeper/keeper_test.go @@ -8,11 +8,11 @@ import ( "github.com/stretchr/testify/suite" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -var testAddress = utils.GenerateAccAddressForTest().String() +var testAddress = addressutils.GenerateAccAddressForTest().String() func init() { ibctesting.DefaultTestingAppInit = app.SetupTestingApp diff --git a/x/claimsmanager/types/claimsmanager_test.go b/x/claimsmanager/types/claimsmanager_test.go index ac8ef1619..2178cd5f6 100644 --- a/x/claimsmanager/types/claimsmanager_test.go +++ b/x/claimsmanager/types/claimsmanager_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) @@ -37,7 +37,7 @@ func TestClaim_ValidateBasic(t *testing.T) { { "invalid_chain_id", fields{ - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainID: "", Amount: 10000, }, @@ -46,7 +46,7 @@ func TestClaim_ValidateBasic(t *testing.T) { { "invalid_chain_id", fields{ - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainID: "", Amount: 10000, }, @@ -55,7 +55,7 @@ func TestClaim_ValidateBasic(t *testing.T) { { "invalid_amount", fields{ - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainID: "testzone-1", Amount: 0, }, @@ -64,7 +64,7 @@ func TestClaim_ValidateBasic(t *testing.T) { { "valid", fields{ - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainID: "testzone-1", Amount: 1000000, }, diff --git a/x/claimsmanager/types/codec.go b/x/claimsmanager/types/codec.go index fdc302f4f..a0a97fc44 100644 --- a/x/claimsmanager/types/codec.go +++ b/x/claimsmanager/types/codec.go @@ -9,6 +9,7 @@ import ( "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/balancer" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/stableswap" ) var ( @@ -22,6 +23,7 @@ func RegisterLegacyAminoCodec(_ *codec.LegacyAmino) { func RegisterInterfaces(registry types.InterfaceRegistry) { gamm.RegisterInterfaces(registry) balancer.RegisterInterfaces(registry) + stableswap.RegisterInterfaces(registry) // cosmos.base.v1beta1.Msg registry.RegisterImplementations( diff --git a/x/claimsmanager/types/genesis_test.go b/x/claimsmanager/types/genesis_test.go index 1491a3634..63d526959 100644 --- a/x/claimsmanager/types/genesis_test.go +++ b/x/claimsmanager/types/genesis_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) @@ -43,7 +43,7 @@ func TestGenesisState_Validate(t *testing.T) { Params: types.DefaultParams(), Claims: []*types.Claim{ { - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainId: "testzone-1", Amount: 0, }, @@ -57,7 +57,7 @@ func TestGenesisState_Validate(t *testing.T) { Params: types.DefaultParams(), Claims: []*types.Claim{ { - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainId: "testzone-1", Amount: 1000000, }, diff --git a/x/claimsmanager/types/keys_test.go b/x/claimsmanager/types/keys_test.go index d5d87d974..ad1e6f408 100644 --- a/x/claimsmanager/types/keys_test.go +++ b/x/claimsmanager/types/keys_test.go @@ -5,12 +5,12 @@ import ( "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) func TestKeys(t *testing.T) { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() // zone prefixClaim := types.GetPrefixClaim("testzone-1") @@ -34,7 +34,7 @@ func TestKeys(t *testing.T) { } func TestLastEpochKeys(t *testing.T) { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() // zone prefixClaim := types.GetPrefixLastEpochClaim("testzone-1") diff --git a/x/interchainquery/types/msgs_test.go b/x/interchainquery/types/msgs_test.go index b4497f625..f4a968ae8 100644 --- a/x/interchainquery/types/msgs_test.go +++ b/x/interchainquery/types/msgs_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainquery/keeper" "github.com/ingenuity-build/quicksilver/x/interchainquery/types" ) @@ -21,7 +21,7 @@ var ( chainB *ibctesting.TestChain path *ibctesting.Path - testAddress sdk.AccAddress = utils.GenerateAccAddressForTest() + testAddress sdk.AccAddress = addressutils.GenerateAccAddressForTest() ) func init() { diff --git a/x/interchainstaking/keeper/callbacks.go b/x/interchainstaking/keeper/callbacks.go index c9b423c79..616006a54 100644 --- a/x/interchainstaking/keeper/callbacks.go +++ b/x/interchainstaking/keeper/callbacks.go @@ -11,7 +11,6 @@ import ( sdkioerrors "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/cosmos/cosmos-sdk/types/tx" "google.golang.org/protobuf/encoding/protowire" @@ -26,6 +25,7 @@ import ( tmtypes "github.com/tendermint/tendermint/types" "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icqtypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -163,11 +163,11 @@ func DelegationCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes. if err != nil { return err } - validatorAddress, err := bech32.ConvertAndEncode(zone.GetValoperPrefix(), validator) + validatorAddress, err := addressutils.EncodeAddressToBech32(zone.GetValoperPrefix(), validator) if err != nil { return err } - delegatorAddress, err := bech32.ConvertAndEncode(zone.GetAccountPrefix(), delegator) + delegatorAddress, err := addressutils.EncodeAddressToBech32(zone.GetAccountPrefix(), delegator) if err != nil { return err } @@ -180,7 +180,7 @@ func DelegationCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes. } return nil } - valAddrBytes, err := utils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) + valAddrBytes, err := addressutils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) if err != nil { return err } @@ -494,7 +494,7 @@ func AccountBalanceCallback(k *Keeper, ctx sdk.Context, args []byte, query icqty return err } - address, err := bech32.ConvertAndEncode(zone.AccountPrefix, accAddr) + address, err := addressutils.EncodeAddressToBech32(zone.AccountPrefix, accAddr) if err != nil { return err } @@ -536,7 +536,7 @@ func DelegationAccountBalanceCallback(k *Keeper, ctx sdk.Context, args []byte, q k.Logger(ctx).Debug("invalid coin for zone", "zone", zone.ChainId, "err", err) return err } - address, err := bech32.ConvertAndEncode(zone.AccountPrefix, accAddr) + address, err := addressutils.EncodeAddressToBech32(zone.AccountPrefix, accAddr) if err != nil { return err } diff --git a/x/interchainstaking/keeper/callbacks_test.go b/x/interchainstaking/keeper/callbacks_test.go index f7e093535..07a57acd9 100644 --- a/x/interchainstaking/keeper/callbacks_test.go +++ b/x/interchainstaking/keeper/callbacks_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icqtypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" @@ -30,7 +30,7 @@ const ( ) func (suite *KeeperTestSuite) TestHandleValsetCallback() { - newVal := utils.GenerateValAddressForTest() + newVal := addressutils.GenerateValAddressForTest() tests := []struct { name string @@ -345,7 +345,7 @@ func (suite *KeeperTestSuite) TestHandleValidatorCallbackNilValue() { } func (suite *KeeperTestSuite) TestHandleValidatorCallback() { - newVal := utils.GenerateAccAddressForTestWithPrefix("cosmosvaloper") + newVal := addressutils.GenerateAddressForTestWithPrefix("cosmosvaloper") zone := icstypes.Zone{ConnectionId: "connection-0", ChainId: "cosmoshub-4", AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom", Is_118: true} suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetValidator(suite.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetValidator(suite.chainA.GetContext(), zone.ChainId, icstypes.Validator{ValoperAddress: "cosmosvaloper156gqf9837u7d4c4678yt3rl4ls9c5vuursrrzf", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000)}) @@ -400,7 +400,7 @@ func (suite *KeeperTestSuite) TestHandleValidatorCallback() { zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, zone.ChainId) suite.True(found) - valAddrBytes, err := utils.ValAddressFromBech32(test.expected.ValoperAddress, zone.GetValoperPrefix()) + valAddrBytes, err := addressutils.ValAddressFromBech32(test.expected.ValoperAddress, zone.GetValoperPrefix()) suite.Require().NoError(err) val, found := quicksilver.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) suite.True(found) @@ -665,7 +665,7 @@ func (suite *KeeperTestSuite) TestHandleRewardsCallbackNonDelegator() { zone.WithdrawalWaitgroup++ quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) - user := utils.GenerateAccAddressForTest() + user := addressutils.GenerateAccAddressForTest() queryReq := distrtypes.QueryDelegationTotalRewardsRequest{ DelegatorAddress: user.String(), @@ -1130,7 +1130,8 @@ func TestValsetCallbackNilValidatorReqPagination(t *testing.T) { ctx := suite.chainA.GetContext() data := []byte("\x12\"\n 00000000000000000000000000000000") - _ = keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID}) + err := keeper.ValsetCallback(&quicksilver.InterchainstakingKeeper, ctx, data, icqtypes.Query{ChainId: suite.chainB.ChainID}) + suite.Require().NoError(err) } func TestDelegationsCallbackAllPresentNoChange(t *testing.T) { @@ -1356,9 +1357,9 @@ func TestDelegationCallbackNew(t *testing.T) { data := cdc.MustMarshal(&response) - delAddr, err := utils.AccAddressFromBech32(zone.DelegationAddress.Address, "") + delAddr, err := addressutils.AccAddressFromBech32(zone.DelegationAddress.Address, "") suite.Require().NoError(err) - valAddr, err := utils.ValAddressFromBech32(vals[3].OperatorAddress, "") + valAddr, err := addressutils.ValAddressFromBech32(vals[3].OperatorAddress, "") suite.Require().NoError(err) bz := stakingtypes.GetDelegationKey(delAddr, valAddr) @@ -1395,9 +1396,9 @@ func TestDelegationCallbackUpdate(t *testing.T) { data := cdc.MustMarshal(&response) - delAddr, err := utils.AccAddressFromBech32(zone.DelegationAddress.Address, "") + delAddr, err := addressutils.AccAddressFromBech32(zone.DelegationAddress.Address, "") suite.Require().NoError(err) - valAddr, err := utils.ValAddressFromBech32(vals[3].OperatorAddress, "") + valAddr, err := addressutils.ValAddressFromBech32(vals[3].OperatorAddress, "") suite.Require().NoError(err) bz := stakingtypes.GetDelegationKey(delAddr, valAddr) @@ -1434,9 +1435,9 @@ func TestDelegationCallbackNoOp(t *testing.T) { data := cdc.MustMarshal(&response) - delAddr, err := utils.AccAddressFromBech32(zone.DelegationAddress.Address, "") + delAddr, err := addressutils.AccAddressFromBech32(zone.DelegationAddress.Address, "") suite.Require().NoError(err) - valAddr, err := utils.ValAddressFromBech32(vals[3].OperatorAddress, "") + valAddr, err := addressutils.ValAddressFromBech32(vals[3].OperatorAddress, "") suite.Require().NoError(err) bz := stakingtypes.GetDelegationKey(delAddr, valAddr) ctx = suite.chainA.GetContext() @@ -1473,9 +1474,9 @@ func TestDelegationCallbackRemove(t *testing.T) { data := cdc.MustMarshal(&response) - delAddr, err := utils.AccAddressFromBech32(zone.DelegationAddress.Address, "") + delAddr, err := addressutils.AccAddressFromBech32(zone.DelegationAddress.Address, "") suite.Require().NoError(err) - valAddr, err := utils.ValAddressFromBech32(vals[3].OperatorAddress, "") + valAddr, err := addressutils.ValAddressFromBech32(vals[3].OperatorAddress, "") suite.Require().NoError(err) bz := stakingtypes.GetDelegationKey(delAddr, valAddr) @@ -1584,7 +1585,7 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallback() { delAddr := zone.DelegationAddress.Address - accAddr, err := utils.AccAddressFromBech32(delAddr, "cosmos") + accAddr, err := addressutils.AccAddressFromBech32(delAddr, "cosmos") suite.Require().NoError(err) data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("qck")...) diff --git a/x/interchainstaking/keeper/delegation_test.go b/x/interchainstaking/keeper/delegation_test.go index c8df21314..13df4b099 100644 --- a/x/interchainstaking/keeper/delegation_test.go +++ b/x/interchainstaking/keeper/delegation_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -101,14 +101,14 @@ type delegationUpdate struct { } func (suite *KeeperTestSuite) TestUpdateDelegation() { - del1 := utils.GenerateAccAddressForTest() + del1 := addressutils.GenerateAccAddressForTest() - val1 := utils.GenerateValAddressForTest() - val2 := utils.GenerateValAddressForTest() - val3 := utils.GenerateValAddressForTest() - val4 := utils.GenerateValAddressForTest() - val5 := utils.GenerateValAddressForTest() - val6 := utils.GenerateValAddressForTest() + val1 := addressutils.GenerateValAddressForTest() + val2 := addressutils.GenerateValAddressForTest() + val3 := addressutils.GenerateValAddressForTest() + val4 := addressutils.GenerateValAddressForTest() + val5 := addressutils.GenerateValAddressForTest() + val6 := addressutils.GenerateValAddressForTest() tests := []struct { name string @@ -231,8 +231,8 @@ func (suite *KeeperTestSuite) TestStoreGetDeleteDelegation() { zone, found := qApp.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) suite.Require().True(found) - delegator := utils.GenerateAccAddressForTest() - validator := utils.GenerateValAddressForTest() + delegator := addressutils.GenerateAccAddressForTest() + validator := addressutils.GenerateValAddressForTest() _, found = qApp.InterchainstakingKeeper.GetDelegation(ctx, &zone, delegator.String(), validator.String()) suite.Require().False(found) @@ -256,7 +256,7 @@ func (suite *KeeperTestSuite) TestStoreGetDeleteDelegation() { } func (suite *KeeperTestSuite) TestFlushOutstandingDelegations() { - userAddress := utils.GenerateAccAddressForTest().String() + userAddress := addressutils.GenerateAccAddressForTest().String() denom := "uatom" tests := []struct { name string diff --git a/x/interchainstaking/keeper/fuzz_test.go b/x/interchainstaking/keeper/fuzz_test.go index 92cf06143..d7e63f55d 100644 --- a/x/interchainstaking/keeper/fuzz_test.go +++ b/x/interchainstaking/keeper/fuzz_test.go @@ -8,7 +8,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icqtypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" @@ -94,7 +94,7 @@ func FuzzZones(f *testing.F) { func FuzzValsetCallback(f *testing.F) { // 1. Generate the seeds. - newVal := utils.GenerateValAddressForTest() + newVal := addressutils.GenerateValAddressForTest() valSetFuncs := []func(in stakingtypes.Validators) stakingtypes.QueryValidatorsResponse{ func(in stakingtypes.Validators) stakingtypes.QueryValidatorsResponse { val := in[0] diff --git a/x/interchainstaking/keeper/ibc_packet_handlers.go b/x/interchainstaking/keeper/ibc_packet_handlers.go index 91c8abdb6..67329436f 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers.go @@ -26,6 +26,7 @@ import ( lsmstakingtypes "github.com/iqlusioninc/liquidity-staking-module/x/staking/types" "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" queryTypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -604,11 +605,11 @@ func (k *Keeper) HandleBeginRedelegate(ctx sdk.Context, msg sdk.Msg, completion tgtDelegation.RedelegationEnd = completion.Unix() // this field should be a timestamp, but let's avoid unnecessary state changes. k.SetDelegation(ctx, zone, tgtDelegation) - delAddr, err := utils.AccAddressFromBech32(redelegateMsg.DelegatorAddress, zone.AccountPrefix) + delAddr, err := addressutils.AccAddressFromBech32(redelegateMsg.DelegatorAddress, zone.AccountPrefix) if err != nil { return err } - valAddr, err := utils.ValAddressFromBech32(redelegateMsg.ValidatorDstAddress, zone.AccountPrefix+"valoper") + valAddr, err := addressutils.ValAddressFromBech32(redelegateMsg.ValidatorDstAddress, zone.AccountPrefix+"valoper") if err != nil { return err } @@ -635,7 +636,7 @@ func (k *Keeper) HandleBeginRedelegate(ctx sdk.Context, msg sdk.Msg, completion srcDelegation.Amount = tgtDelegation.Amount.Sub(redelegateMsg.Amount) k.SetDelegation(ctx, zone, srcDelegation) - valAddr, err = utils.ValAddressFromBech32(redelegateMsg.ValidatorDstAddress, zone.AccountPrefix+"valoper") + valAddr, err = addressutils.ValAddressFromBech32(redelegateMsg.ValidatorDstAddress, zone.AccountPrefix+"valoper") if err != nil { return err } @@ -713,11 +714,11 @@ func (k *Keeper) HandleUndelegate(ctx sdk.Context, msg sdk.Msg, completion time. k.UpdateWithdrawalRecordStatus(ctx, &record, WithdrawStatusUnbond) } - delAddr, err := utils.AccAddressFromBech32(undelegateMsg.DelegatorAddress, "") + delAddr, err := addressutils.AccAddressFromBech32(undelegateMsg.DelegatorAddress, "") if err != nil { return err } - valAddr, err := utils.ValAddressFromBech32(undelegateMsg.ValidatorAddress, "") + valAddr, err := addressutils.ValAddressFromBech32(undelegateMsg.ValidatorAddress, "") if err != nil { return err } diff --git a/x/interchainstaking/keeper/ibc_packet_handlers_test.go b/x/interchainstaking/keeper/ibc_packet_handlers_test.go index 01d3c569d..8ef16c156 100644 --- a/x/interchainstaking/keeper/ibc_packet_handlers_test.go +++ b/x/interchainstaking/keeper/ibc_packet_handlers_test.go @@ -9,7 +9,6 @@ import ( sdkmath "cosmossdk.io/math" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -20,7 +19,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -30,7 +29,7 @@ func TestHandleMsgTransferGood(t *testing.T) { err := quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("denom", sdk.NewInt(100)))) require.NoError(t, err) - sender := utils.GenerateAccAddressForTest() + sender := addressutils.GenerateAccAddressForTest() senderAddr, err := sdk.Bech32ifyAddressBytes("cosmos", sender) require.NoError(t, err) @@ -67,10 +66,10 @@ func TestHandleMsgTransferBadType(t *testing.T) { } func TestHandleMsgTransferBadRecipient(t *testing.T) { - recipient := utils.GenerateAccAddressForTest() + recipient := addressutils.GenerateAccAddressForTest() quicksilver, ctx := app.GetAppWithContext(t, true) - sender := utils.GenerateAccAddressForTest() + sender := addressutils.GenerateAccAddressForTest() senderAddr, err := sdk.Bech32ifyAddressBytes("cosmos", sender) require.NoError(t, err) @@ -84,14 +83,6 @@ func TestHandleMsgTransferBadRecipient(t *testing.T) { require.Error(t, quicksilver.InterchainstakingKeeper.HandleMsgTransfer(ctx, &transferMsg)) } -func mustGetTestBech32Address(hrp string) string { - outAddr, err := bech32.ConvertAndEncode(hrp, utils.GenerateAccAddressForTest()) - if err != nil { - panic(err) - } - return outAddr -} - func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() { tests := []struct { name string @@ -109,14 +100,14 @@ func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() { return []icstypes.WithdrawalRecord{ { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ {Valoper: vals[0], Amount: 1000000}, {Valoper: vals[1], Amount: 1000000}, {Valoper: vals[2], Amount: 1000000}, {Valoper: vals[3], Amount: 1000000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(4000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(4000000)), Txhash: "7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", @@ -162,14 +153,14 @@ func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() { return []icstypes.WithdrawalRecord{ { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ {Valoper: vals[0], Amount: 1000000}, {Valoper: vals[1], Amount: 1000000}, {Valoper: vals[2], Amount: 1000000}, {Valoper: vals[3], Amount: 1000000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(4000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(4000000)), Txhash: "7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", @@ -177,14 +168,14 @@ func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() { }, { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ {Valoper: vals[0], Amount: 5000000}, {Valoper: vals[1], Amount: 2500000}, {Valoper: vals[2], Amount: 5000000}, {Valoper: vals[3], Amount: 2500000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(15000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(15000000)), Txhash: "d786f7d4c94247625c2882e921a790790eb77a00d0534d5c3154d0a9c5ab68f5", @@ -230,14 +221,14 @@ func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() { return []icstypes.WithdrawalRecord{ { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ {Valoper: vals[0], Amount: 1000000}, {Valoper: vals[1], Amount: 1000000}, {Valoper: vals[2], Amount: 1000000}, {Valoper: vals[3], Amount: 1000000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(4000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(4000000)), Txhash: "7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", @@ -293,14 +284,14 @@ func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() { return []icstypes.WithdrawalRecord{ { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ {Valoper: vals[0], Amount: 5000000}, {Valoper: vals[1], Amount: 2500000}, {Valoper: vals[2], Amount: 5000000}, {Valoper: vals[3], Amount: 2500000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(15000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(15000000)), Txhash: "d786f7d4c94247625c2882e921a790790eb77a00d0534d5c3154d0a9c5ab68f5", @@ -308,14 +299,14 @@ func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() { }, { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ {Valoper: vals[0], Amount: 1000000}, {Valoper: vals[1], Amount: 1000000}, {Valoper: vals[2], Amount: 1000000}, {Valoper: vals[3], Amount: 1000000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(4000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(4000000)), Txhash: "7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", @@ -389,7 +380,7 @@ func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() { for _, delegation := range delegations { quicksilver.InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) - valAddrBytes, err := utils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) + valAddrBytes, err := addressutils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) suite.Require().NoError(err) val, _ := quicksilver.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) val.VotingPower = val.VotingPower.Add(delegation.Amount.Amount) @@ -446,14 +437,14 @@ func (suite *KeeperTestSuite) TestHandleWithdrawForUser() { return []icstypes.WithdrawalRecord{ { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(4000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(4000000)), Txhash: "7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", @@ -471,14 +462,14 @@ func (suite *KeeperTestSuite) TestHandleWithdrawForUser() { return []icstypes.WithdrawalRecord{ { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(4000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(4000000)), Txhash: "7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", @@ -498,14 +489,14 @@ func (suite *KeeperTestSuite) TestHandleWithdrawForUser() { return []icstypes.WithdrawalRecord{ { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1000000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(4000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(4000000)), Txhash: "7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", @@ -513,14 +504,14 @@ func (suite *KeeperTestSuite) TestHandleWithdrawForUser() { }, { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 5000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1250000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 5000000}, - {Valoper: utils.GenerateValAddressForTest().String(), Amount: 1250000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 5000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1250000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 5000000}, + {Valoper: addressutils.GenerateValAddressForTest().String(), Amount: 1250000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(15000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(15000000)), Txhash: "d786f7d4c94247625c2882e921a790790eb77a00d0534d5c3154d0a9c5ab68f5", @@ -586,8 +577,8 @@ func (suite *KeeperTestSuite) TestHandleWithdrawForUser() { } func (suite *KeeperTestSuite) TestHandleWithdrawForUserLSM() { - v1 := utils.GenerateValAddressForTest().String() - v2 := utils.GenerateValAddressForTest().String() + v1 := addressutils.GenerateValAddressForTest().String() + v2 := addressutils.GenerateValAddressForTest().String() tests := []struct { name string records func(zone *icstypes.Zone) []icstypes.WithdrawalRecord @@ -601,12 +592,12 @@ func (suite *KeeperTestSuite) TestHandleWithdrawForUserLSM() { return []icstypes.WithdrawalRecord{ { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ {Valoper: v1, Amount: 1000000}, {Valoper: v2, Amount: 1000000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(2000000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(2000000)), Txhash: "7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", @@ -627,12 +618,12 @@ func (suite *KeeperTestSuite) TestHandleWithdrawForUserLSM() { return []icstypes.WithdrawalRecord{ { ChainId: zone.ChainId, - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ {Valoper: v1, Amount: 1000000}, {Valoper: v2, Amount: 1500000}, }, - Recipient: mustGetTestBech32Address(zone.AccountPrefix), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(2500000))), BurnAmount: sdk.NewCoin("uqatom", sdk.NewInt(2500000)), Txhash: "7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D", @@ -757,8 +748,8 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { hash1 := fmt.Sprintf("%x", sha256.Sum256([]byte{0x01})) hash2 := fmt.Sprintf("%x", sha256.Sum256([]byte{0x02})) hash3 := fmt.Sprintf("%x", sha256.Sum256([]byte{0x03})) - delegator1 := utils.GenerateAccAddressForTest().String() - delegator2 := utils.GenerateAccAddressForTest().String() + delegator1 := addressutils.GenerateAccAddressForTest().String() + delegator2 := addressutils.GenerateAccAddressForTest().String() tests := []struct { name string @@ -787,7 +778,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Amount: 1000, }, }, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(2000))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(1800)), Txhash: hash1, @@ -828,7 +819,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Amount: 1000, }, }, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(900)), Txhash: hash1, @@ -838,7 +829,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: nil, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(900)), Txhash: fmt.Sprintf("%064d", 1), @@ -862,7 +853,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Amount: 1000, }, }, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(900)), Txhash: hash1, @@ -897,7 +888,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: nil, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(900)), Txhash: hash1, @@ -925,7 +916,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Amount: 500, }, }, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1500))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(1350)), Txhash: hash1, @@ -944,7 +935,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Amount: 2000, }, }, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(3000))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(2700)), Txhash: hash2, @@ -963,7 +954,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Amount: 400, }, }, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(900)), Txhash: hash3, @@ -1004,7 +995,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Amount: 1000, }, }, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(900)), Txhash: hash1, @@ -1019,7 +1010,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Amount: 1000, }, }, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(900)), Txhash: hash2, @@ -1034,7 +1025,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { Amount: 600, }, }, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(600))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(540)), Txhash: hash3, @@ -1044,7 +1035,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: nil, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(500))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(450)), Txhash: fmt.Sprintf("%064d", 1), @@ -1054,7 +1045,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { ChainId: suite.chainB.ChainID, Delegator: delegator2, Distribution: nil, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(2000))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(1800)), Txhash: fmt.Sprintf("%064d", 2), @@ -1064,7 +1055,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { ChainId: suite.chainB.ChainID, Delegator: delegator1, Distribution: nil, - Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(400))), BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(360)), Txhash: fmt.Sprintf("%064d", 3), @@ -1089,7 +1080,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { // Amount: 1000, // }, // }, - // Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + // Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), // Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), // BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(1000).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()), // Txhash: hash1, @@ -1108,7 +1099,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { // Amount: 456, // }, // }, - // Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + // Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), // Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(579))), // BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(579).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()), // Txhash: hash2, @@ -1161,7 +1152,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { // ChainId: s.chainB.ChainID, // Delegator: delegator1, // Distribution: nil, - // Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + // Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), // Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))), // BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(1000).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()), // Txhash: hash1, @@ -1171,7 +1162,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { // ChainId: s.chainB.ChainID, // Delegator: delegator2, // Distribution: nil, - // Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + // Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), // Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(123))), // BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(123).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()), // Txhash: fmt.Sprintf("%064d", 1), @@ -1186,7 +1177,7 @@ func (suite *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() { // Amount: 456, // }, // }, - // Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()), + // Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.GetAccountPrefix()), // Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(456))), // BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(456).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()), // Txhash: hash2, @@ -1273,7 +1264,7 @@ func (suite *KeeperTestSuite) TestRebalanceDueToIntentChange() { } vals := quicksilver.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) for _, val := range vals { - valoper, _ := utils.ValAddressFromBech32(val.ValoperAddress, "cosmosvaloper") + valoper, _ := addressutils.ValAddressFromBech32(val.ValoperAddress, "cosmosvaloper") quicksilver.InterchainstakingKeeper.DeleteValidator(ctx, zone.ChainId, valoper) } @@ -1316,7 +1307,7 @@ func (suite *KeeperTestSuite) TestRebalanceDueToIntentChange() { } for _, delegation := range delegations { quicksilver.InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) - addressBytes, err := utils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) + addressBytes, err := addressutils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) suite.Require().NoError(err) val, _ := quicksilver.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, addressBytes) val.VotingPower = val.VotingPower.Add(delegation.Amount.Amount) @@ -1403,7 +1394,7 @@ func (suite *KeeperTestSuite) TestRebalanceDueToDelegationChange() { } vals := quicksilver.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) for _, val := range vals { - valoper, _ := utils.ValAddressFromBech32(val.ValoperAddress, "cosmosvaloper") + valoper, _ := addressutils.ValAddressFromBech32(val.ValoperAddress, "cosmosvaloper") quicksilver.InterchainstakingKeeper.DeleteValidator(ctx, zone.ChainId, valoper) } @@ -1443,7 +1434,7 @@ func (suite *KeeperTestSuite) TestRebalanceDueToDelegationChange() { } for _, delegation := range delegations { quicksilver.InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) - valAddrBytes, err := utils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) + valAddrBytes, err := addressutils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) suite.Require().NoError(err) val, found := quicksilver.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) @@ -1531,7 +1522,7 @@ func (suite *KeeperTestSuite) Test_v045Callback() { setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) ([]sdk.Msg, []byte) { err := quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("denom", sdk.NewInt(100)))) suite.Require().NoError(err) - sender := utils.GenerateAccAddressForTest() + sender := addressutils.GenerateAccAddressForTest() senderAddr, err := sdk.Bech32ifyAddressBytes("cosmos", sender) suite.Require().NoError(err) @@ -1651,7 +1642,7 @@ func (suite *KeeperTestSuite) Test_v046Callback() { setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) ([]sdk.Msg, *codectypes.Any) { err := quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("denom", sdk.NewInt(100)))) suite.Require().NoError(err) - sender := utils.GenerateAccAddressForTest() + sender := addressutils.GenerateAccAddressForTest() senderAddr, err := sdk.Bech32ifyAddressBytes("cosmos", sender) suite.Require().NoError(err) diff --git a/x/interchainstaking/keeper/intent.go b/x/interchainstaking/keeper/intent.go index d6d8cb4b2..1ff2d3779 100644 --- a/x/interchainstaking/keeper/intent.go +++ b/x/interchainstaking/keeper/intent.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ingenuity-build/quicksilver/internal/multierror" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" prtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -219,7 +219,7 @@ func (k msgServer) validateValidatorIntents(ctx sdk.Context, zone types.Zone, in for i, intent := range intents { var valAddrBytes []byte - valAddrBytes, err := utils.ValAddressFromBech32(intent.ValoperAddress, zone.GetValoperPrefix()) + valAddrBytes, err := addressutils.ValAddressFromBech32(intent.ValoperAddress, zone.GetValoperPrefix()) if err != nil { return err } diff --git a/x/interchainstaking/keeper/intent_test.go b/x/interchainstaking/keeper/intent_test.go index a01ecaf0c..b31abc3f8 100644 --- a/x/interchainstaking/keeper/intent_test.go +++ b/x/interchainstaking/keeper/intent_test.go @@ -5,13 +5,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) var ( - user1 = utils.GenerateAccAddressForTest() - user2 = utils.GenerateAccAddressForTest() + user1 = addressutils.GenerateAccAddressForTest() + user2 = addressutils.GenerateAccAddressForTest() ) func (suite *KeeperTestSuite) TestKeeper_IntentStore() { diff --git a/x/interchainstaking/keeper/keeper.go b/x/interchainstaking/keeper/keeper.go index b8f48ef80..489faaf1c 100644 --- a/x/interchainstaking/keeper/keeper.go +++ b/x/interchainstaking/keeper/keeper.go @@ -27,6 +27,7 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" "github.com/tendermint/tendermint/libs/log" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icqtypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" config "github.com/ingenuity-build/quicksilver/cmd/config" @@ -192,7 +193,7 @@ func (k *Keeper) SetValidatorsForZone(ctx sdk.Context, data []byte, icqQuery icq } for _, validator := range validatorsRes.Validators { - addr, err := utils.ValAddressFromBech32(validator.OperatorAddress, "") + addr, err := addressutils.ValAddressFromBech32(validator.OperatorAddress, "") if err != nil { return err } @@ -228,7 +229,7 @@ func (k *Keeper) SetValidatorForZone(ctx sdk.Context, zone *types.Zone, data []b return err } - valAddrBytes, err := utils.ValAddressFromBech32(validator.OperatorAddress, zone.GetValoperPrefix()) + valAddrBytes, err := addressutils.ValAddressFromBech32(validator.OperatorAddress, zone.GetValoperPrefix()) if err != nil { return err } @@ -584,7 +585,7 @@ func (k *Keeper) GetAggregateIntentOrDefault(ctx sdk.Context, z *types.Zone) (ty // filter intents here... // check validators for tombstoned for _, v := range intents { - valAddrBytes, err := utils.ValAddressFromBech32(v.ValoperAddress, z.GetValoperPrefix()) + valAddrBytes, err := addressutils.ValAddressFromBech32(v.ValoperAddress, z.GetValoperPrefix()) if err != nil { return nil, err } diff --git a/x/interchainstaking/keeper/keeper_test.go b/x/interchainstaking/keeper/keeper_test.go index 42624786a..088a4705c 100644 --- a/x/interchainstaking/keeper/keeper_test.go +++ b/x/interchainstaking/keeper/keeper_test.go @@ -6,7 +6,6 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" ibctesting "github.com/cosmos/ibc-go/v5/testing" @@ -20,13 +19,14 @@ import ( tmclienttypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" + "github.com/ingenuity-build/quicksilver/utils/randomutils" ics "github.com/ingenuity-build/quicksilver/x/interchainstaking" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -var testAddress = utils.GenerateAccAddressForTest().String() +var testAddress = addressutils.GenerateAccAddressForTest().String() func init() { ibctesting.DefaultTestingAppInit = app.SetupTestingApp @@ -169,7 +169,7 @@ func (suite *KeeperTestSuite) setupChannelForICA(ctx sdk.Context, chainID, conne return err } - addr, err := bech32.ConvertAndEncode(remotePrefix, utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32(remotePrefix, addressutils.GenerateAccAddressForTest()) if err != nil { return err } @@ -188,7 +188,7 @@ func (suite *KeeperTestSuite) giveFunds(ctx sdk.Context, denom string, amount in ) err := quicksilver.MintKeeper.MintCoins(ctx, balance) suite.Require().NoError(err) - addr, err := utils.AccAddressFromBech32(address, "") + addr, err := addressutils.AccAddressFromBech32(address, "") suite.Require().NoError(err) err = quicksilver.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, balance) suite.Require().NoError(err) @@ -274,7 +274,7 @@ func (suite *KeeperTestSuite) TestGetUnbondingAmount() { name: "one unbonding withdrawal", records: func(zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}) return out }, expected: math.NewInt(3000000), @@ -283,7 +283,7 @@ func (suite *KeeperTestSuite) TestGetUnbondingAmount() { name: "one non-unbonding withdrawal", records: func(zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusQueued, Txhash: utils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusQueued, Txhash: randomutils.GenerateRandomHashAsHex()}) return out }, expected: math.ZeroInt(), @@ -293,9 +293,9 @@ func (suite *KeeperTestSuite) TestGetUnbondingAmount() { records: func(zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) out = append(out, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, ) return out }, @@ -306,9 +306,9 @@ func (suite *KeeperTestSuite) TestGetUnbondingAmount() { records: func(zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) out = append(out, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusQueued, Txhash: utils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusCompleted, Txhash: utils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusQueued, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusCompleted, Txhash: randomutils.GenerateRandomHashAsHex()}, ) return out }, @@ -378,7 +378,7 @@ func (suite *KeeperTestSuite) TestGetRatio() { name: "one withdrawal, no delegation, expect 1.0", records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}) return out }, delegations: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.Delegation { @@ -392,7 +392,7 @@ func (suite *KeeperTestSuite) TestGetRatio() { name: "one withdrawals, one delegation, one unbonding, expect 1.0", records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}) return out }, delegations: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.Delegation { @@ -408,7 +408,7 @@ func (suite *KeeperTestSuite) TestGetRatio() { name: "one non-unbond withdrawals, one delegation, one unbonding, expect 1.0", records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusCompleted, Txhash: utils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusCompleted, Txhash: randomutils.GenerateRandomHashAsHex()}) return out }, delegations: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.Delegation { @@ -425,9 +425,9 @@ func (suite *KeeperTestSuite) TestGetRatio() { records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) out = append(out, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, ) return out }, @@ -445,8 +445,8 @@ func (suite *KeeperTestSuite) TestGetRatio() { records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) out = append(out, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, ) return out }, @@ -463,7 +463,7 @@ func (suite *KeeperTestSuite) TestGetRatio() { name: "multi unbonding withdrawal, delegation, gt 1.0", records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: utils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}) return out }, delegations: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.Delegation { diff --git a/x/interchainstaking/keeper/msg_server.go b/x/interchainstaking/keeper/msg_server.go index 9d679dcee..38e4426b0 100644 --- a/x/interchainstaking/keeper/msg_server.go +++ b/x/interchainstaking/keeper/msg_server.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -55,7 +55,7 @@ func (k msgServer) RequestRedemption(goCtx context.Context, msg *types.MsgReques } // does destination address match the prefix registered against the zone? - if _, err := utils.AccAddressFromBech32(msg.DestinationAddress, zone.AccountPrefix); err != nil { + if _, err := addressutils.AccAddressFromBech32(msg.DestinationAddress, zone.AccountPrefix); err != nil { return nil, fmt.Errorf("destination address %s does not match expected prefix %s [%w]", msg.DestinationAddress, zone.AccountPrefix, err) } diff --git a/x/interchainstaking/keeper/msg_server_test.go b/x/interchainstaking/keeper/msg_server_test.go index 45b1ee3d1..18d4c34c0 100644 --- a/x/interchainstaking/keeper/msg_server_test.go +++ b/x/interchainstaking/keeper/msg_server_test.go @@ -6,9 +6,8 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -16,7 +15,7 @@ import ( func (suite *KeeperTestSuite) TestRequestRedemption() { var msg icstypes.MsgRequestRedemption - testAccount, err := utils.AccAddressFromBech32(testAddress, "") + testAccount, err := addressutils.AccAddressFromBech32(testAddress, "") suite.Require().NoError(err) tests := []struct { @@ -28,7 +27,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "valid - full claim", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), @@ -42,7 +41,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "valid - full claim (discounted)", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), @@ -61,7 +60,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "valid - full claim (interest)", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), @@ -81,7 +80,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "valid - full claim (interest)", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), @@ -101,7 +100,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "valid - partial claim", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), @@ -115,7 +114,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "valid - partial claim (discounted)", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), @@ -134,7 +133,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "valid - partial claim (interest)", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), @@ -154,7 +153,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "invalid - unbonding not enabled for zone", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), @@ -173,7 +172,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "invalid - wrong denom", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uatom", sdk.NewInt(10000000)), @@ -187,7 +186,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "invalid - insufficient funds", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(1000000000)), @@ -201,7 +200,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "invalid - bad prefix", func() { - addr, err := bech32.ConvertAndEncode("bob", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("bob", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.OneInt()), @@ -215,7 +214,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "invalid - bad from address", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.OneInt()), @@ -229,7 +228,7 @@ func (suite *KeeperTestSuite) TestRequestRedemption() { { "invalid - too many locked tokens", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), diff --git a/x/interchainstaking/keeper/receipt.go b/x/interchainstaking/keeper/receipt.go index 3ce0966ee..37da5562c 100644 --- a/x/interchainstaking/keeper/receipt.go +++ b/x/interchainstaking/keeper/receipt.go @@ -16,6 +16,7 @@ import ( channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v5/modules/core/24-host" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -384,7 +385,7 @@ func (k *Keeper) IterateZoneReceipts(ctx sdk.Context, zone *types.Zone, fn func( func (k *Keeper) UserZoneReceipts(ctx sdk.Context, zone *types.Zone, addr sdk.AccAddress) ([]types.Receipt, error) { receipts := make([]types.Receipt, 0) - bech32Address, err := bech32.ConvertAndEncode(zone.AccountPrefix, addr) + bech32Address, err := addressutils.EncodeAddressToBech32(zone.AccountPrefix, addr) if err != nil { return receipts, err } diff --git a/x/interchainstaking/keeper/receipt_test.go b/x/interchainstaking/keeper/receipt_test.go index 9778bca62..462ef088d 100644 --- a/x/interchainstaking/keeper/receipt_test.go +++ b/x/interchainstaking/keeper/receipt_test.go @@ -9,7 +9,8 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" + "github.com/ingenuity-build/quicksilver/utils/randomutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -24,15 +25,15 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionGood() { zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) suite.Require().True(found) - fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} anymsg, err := codectypes.NewAnyWithValue(&msg) suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} - hash := utils.GenerateRandomHashAsHex() - hash2 := utils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex() + hash2 := randomutils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -62,14 +63,14 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadRecipient() { zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) suite.Require().True(found) - fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} anymsg, err := codectypes.NewAnyWithValue(&msg) suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} - hash := utils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -94,14 +95,14 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMessageType() { zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) suite.Require().True(found) - fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) msg := stakingtypes.MsgDelegate{DelegatorAddress: fromAddress, ValidatorAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000))} anymsg, err := codectypes.NewAnyWithValue(&msg) suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} - hash := utils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -126,7 +127,7 @@ func (suite *KeeperTestSuite) TestHandleReceiptMixedMessageTypeGood() { zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) suite.Require().True(found) - fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} anymsg, err := codectypes.NewAnyWithValue(&msg) @@ -137,7 +138,7 @@ func (suite *KeeperTestSuite) TestHandleReceiptMixedMessageTypeGood() { suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} - hash := utils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -160,8 +161,8 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMixedSender() { // zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) suite.Require().True(found) - fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) - fromAddress2 := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) + fromAddress2 := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} anymsg, err := codectypes.NewAnyWithValue(&msg) @@ -171,7 +172,7 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMixedSender() { // suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} - hash := utils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -196,14 +197,14 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadDenom() { zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) suite.Require().True(found) - fromAddress := utils.GenerateAccAddressForTestWithPrefix(zone.AccountPrefix) + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin("ushit", math.NewInt(1000000)))} anymsg, err := codectypes.NewAnyWithValue(&msg) suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} - hash := utils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex() before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -230,12 +231,12 @@ func (suite *KeeperTestSuite) TestReceiptStore() { zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) suite.Require().True(found) - account1 := utils.GenerateAccAddressForTest() - account2 := utils.GenerateAccAddressForTest() - hash1 := utils.GenerateRandomHashAsHex() - hash2 := utils.GenerateRandomHashAsHex() - hash3 := utils.GenerateRandomHashAsHex() - hash4 := utils.GenerateRandomHashAsHex() + account1 := addressutils.GenerateAccAddressForTest() + account2 := addressutils.GenerateAccAddressForTest() + hash1 := randomutils.GenerateRandomHashAsHex() + hash2 := randomutils.GenerateRandomHashAsHex() + hash3 := randomutils.GenerateRandomHashAsHex() + hash4 := randomutils.GenerateRandomHashAsHex() zone2 := types.Zone{ChainId: "test-1"} diff --git a/x/interchainstaking/keeper/redelegation_record_test.go b/x/interchainstaking/keeper/redelegation_record_test.go index 64aee944e..58e563e01 100644 --- a/x/interchainstaking/keeper/redelegation_record_test.go +++ b/x/interchainstaking/keeper/redelegation_record_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "time" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -11,8 +11,8 @@ func (suite *KeeperTestSuite) TestRedelegationRecordSetGetIterate() { quicksilver := suite.GetQuicksilverApp(suite.chainA) ctx := suite.chainA.GetContext() - testValidatorOne := utils.GenerateAccAddressForTestWithPrefix("cosmosvaloper") - testValidatorTwo := utils.GenerateValAddressForTestWithPrefix("cosmosvaloper") + testValidatorOne := addressutils.GenerateAddressForTestWithPrefix("cosmosvaloper") + testValidatorTwo := addressutils.GenerateAddressForTestWithPrefix("cosmosvaloper") suite.SetupTest() diff --git a/x/interchainstaking/keeper/validator_test.go b/x/interchainstaking/keeper/validator_test.go index a005a3c28..9302bcea5 100644 --- a/x/interchainstaking/keeper/validator_test.go +++ b/x/interchainstaking/keeper/validator_test.go @@ -4,7 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -19,9 +19,9 @@ func (suite *KeeperTestSuite) TestStoreGetDeleteValidator() { zone, found := app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) suite.Require().True(found) - validator := utils.GenerateValAddressForTest() + validator := addressutils.GenerateValAddressForTest() - valAddrBytes, err := utils.ValAddressFromBech32(validator.String(), zone.GetValoperPrefix()) + valAddrBytes, err := addressutils.ValAddressFromBech32(validator.String(), zone.GetValoperPrefix()) suite.Require().NoError(err) _, found = app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) suite.Require().False(found) diff --git a/x/interchainstaking/keeper/zones_test.go b/x/interchainstaking/keeper/zones_test.go index f18007807..da42e07eb 100644 --- a/x/interchainstaking/keeper/zones_test.go +++ b/x/interchainstaking/keeper/zones_test.go @@ -15,7 +15,7 @@ import ( "golang.org/x/exp/maps" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -75,7 +75,7 @@ func TestKeeperWithZonesRoundTrip(t *testing.T) { indexToZone := make(map[int64]types.Zone, nzones) for i := 0; i < nzones; i++ { chainID := fmt.Sprintf("%s%d", chainIDPrefix, i) - delegationAddr := utils.GenerateAccAddressForTestWithPrefix("cosmos") + delegationAddr := addressutils.GenerateAddressForTestWithPrefix("cosmos") zone := types.Zone{ ConnectionId: "conn-test", ChainId: chainID, diff --git a/x/interchainstaking/types/accounts.go b/x/interchainstaking/types/accounts.go index 086ac62a4..1d3a699d8 100644 --- a/x/interchainstaking/types/accounts.go +++ b/x/interchainstaking/types/accounts.go @@ -4,19 +4,18 @@ import ( "errors" sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" ) func NewICAAccount(addr, portID string) (*ICAAccount, error) { - if _, err := utils.AccAddressFromBech32(addr, ""); err != nil { + if _, err := addressutils.AccAddressFromBech32(addr, ""); err != nil { return nil, err } return &ICAAccount{Address: addr, WithdrawalAddress: addr, Balance: sdk.Coins{}, PortName: portID}, nil } func (a *ICAAccount) SetWithdrawalAddress(addr string) error { - if _, err := utils.AccAddressFromBech32(addr, ""); err != nil { + if _, err := addressutils.AccAddressFromBech32(addr, ""); err != nil { return err } a.WithdrawalAddress = addr diff --git a/x/interchainstaking/types/delegation_test.go b/x/interchainstaking/types/delegation_test.go index 6b6b05742..8c6668a97 100644 --- a/x/interchainstaking/types/delegation_test.go +++ b/x/interchainstaking/types/delegation_test.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -43,9 +43,9 @@ func TestRoundtripDelegationMarshalToUnmarshal(t *testing.T) { } func TestSetForValoper(t *testing.T) { - v1 := utils.GenerateValAddressForTest().String() - v2 := utils.GenerateValAddressForTest().String() - v3 := utils.GenerateValAddressForTest().String() + v1 := addressutils.GenerateValAddressForTest().String() + v2 := addressutils.GenerateValAddressForTest().String() + v3 := addressutils.GenerateValAddressForTest().String() intents := types.ValidatorIntents{ {ValoperAddress: v1, Weight: sdk.NewDecWithPrec(10, 1)}, @@ -64,10 +64,10 @@ func TestSetForValoper(t *testing.T) { } func TestNormalizeValidatorIntentsDeterminism(t *testing.T) { - v1 := utils.GenerateValAddressForTest().String() - v2 := utils.GenerateValAddressForTest().String() - v3 := utils.GenerateValAddressForTest().String() - v4 := utils.GenerateValAddressForTest().String() + v1 := addressutils.GenerateValAddressForTest().String() + v2 := addressutils.GenerateValAddressForTest().String() + v3 := addressutils.GenerateValAddressForTest().String() + v4 := addressutils.GenerateValAddressForTest().String() cases := []struct { name string @@ -109,10 +109,10 @@ func TestDetermineAllocationsForDelegation(t *testing.T) { // we auto generate the validator addresses in these tests. any dust gets allocated to the first validator in the list // once sorted alphabetically on valoper. - val1 := utils.GenerateValAddressForTest() - val2 := utils.GenerateValAddressForTest() - val3 := utils.GenerateValAddressForTest() - val4 := utils.GenerateValAddressForTest() + val1 := addressutils.GenerateValAddressForTest() + val2 := addressutils.GenerateValAddressForTest() + val3 := addressutils.GenerateValAddressForTest() + val4 := addressutils.GenerateValAddressForTest() tc := []struct { current map[string]sdkmath.Int diff --git a/x/interchainstaking/types/msgs_test.go b/x/interchainstaking/types/msgs_test.go index ac829eb18..f9bbd8f71 100644 --- a/x/interchainstaking/types/msgs_test.go +++ b/x/interchainstaking/types/msgs_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -155,8 +155,8 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Value: sdk.Coin{ Denom: "stake", }, - DestinationAddress: utils.GenerateAccAddressForTest().String(), - FromAddress: utils.GenerateAccAddressForTest().String(), + DestinationAddress: addressutils.GenerateAccAddressForTest().String(), + FromAddress: addressutils.GenerateAccAddressForTest().String(), }, true, }, @@ -168,7 +168,7 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Amount: sdkmath.OneInt(), }, DestinationAddress: "", - FromAddress: utils.GenerateAccAddressForTest().String(), + FromAddress: addressutils.GenerateAccAddressForTest().String(), }, true, }, @@ -179,7 +179,7 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Denom: "stake", Amount: sdkmath.OneInt(), }, - DestinationAddress: utils.GenerateAccAddressForTest().String(), + DestinationAddress: addressutils.GenerateAccAddressForTest().String(), FromAddress: "", }, true, @@ -191,8 +191,8 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Denom: "stake", Amount: sdkmath.ZeroInt(), }, - DestinationAddress: utils.GenerateAccAddressForTest().String(), - FromAddress: utils.GenerateAccAddressForTest().String(), + DestinationAddress: addressutils.GenerateAccAddressForTest().String(), + FromAddress: addressutils.GenerateAccAddressForTest().String(), }, true, }, @@ -203,8 +203,8 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Denom: "stake", Amount: sdkmath.NewInt(-1), }, - DestinationAddress: utils.GenerateAccAddressForTest().String(), - FromAddress: utils.GenerateAccAddressForTest().String(), + DestinationAddress: addressutils.GenerateAccAddressForTest().String(), + FromAddress: addressutils.GenerateAccAddressForTest().String(), }, true, }, @@ -215,8 +215,8 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Denom: "stake", Amount: sdkmath.OneInt(), }, - DestinationAddress: utils.GenerateAccAddressForTest().String(), - FromAddress: utils.GenerateAccAddressForTest().String(), + DestinationAddress: addressutils.GenerateAccAddressForTest().String(), + FromAddress: addressutils.GenerateAccAddressForTest().String(), }, false, }, diff --git a/x/interchainstaking/types/validator_test.go b/x/interchainstaking/types/validator_test.go index e00e03a20..5b18cc334 100644 --- a/x/interchainstaking/types/validator_test.go +++ b/x/interchainstaking/types/validator_test.go @@ -7,16 +7,16 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) var ( - acc1 = utils.GenerateAccAddressForTest().String() - v1 = utils.GenerateValAddressForTest().String() - v2 = utils.GenerateValAddressForTest().String() - v3 = utils.GenerateValAddressForTest().String() - v4 = utils.GenerateValAddressForTest().String() + acc1 = addressutils.GenerateAccAddressForTest().String() + v1 = addressutils.GenerateValAddressForTest().String() + v2 = addressutils.GenerateValAddressForTest().String() + v3 = addressutils.GenerateValAddressForTest().String() + v4 = addressutils.GenerateValAddressForTest().String() ) func TestSharesToTokens(t *testing.T) { @@ -71,7 +71,7 @@ func TestNormalizeIntentWithEqualIntents(t *testing.T) { } func TestNormalizeIntentWithNonEqualIntents(t *testing.T) { - di := types.DelegatorIntent{Delegator: utils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ + di := types.DelegatorIntent{Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ {ValoperAddress: v1, Weight: sdk.NewDec(5).Quo(sdk.NewDec(50))}, {ValoperAddress: v2, Weight: sdk.NewDec(10).Quo(sdk.NewDec(50))}, {ValoperAddress: v3, Weight: sdk.NewDec(35).Quo(sdk.NewDec(50))}, @@ -84,7 +84,7 @@ func TestNormalizeIntentWithNonEqualIntents(t *testing.T) { } func TestOrdinalizeIntentWithEqualIntents(t *testing.T) { - di := types.DelegatorIntent{Delegator: utils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ + di := types.DelegatorIntent{Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ {ValoperAddress: v1, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, {ValoperAddress: v2, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, {ValoperAddress: v3, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, @@ -95,7 +95,7 @@ func TestOrdinalizeIntentWithEqualIntents(t *testing.T) { } func TestOrdinalizeIntentWithNonEqualIntents(t *testing.T) { - di := types.DelegatorIntent{Delegator: utils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ + di := types.DelegatorIntent{Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ {ValoperAddress: v1, Weight: sdk.NewDec(5).Quo(sdk.NewDec(50))}, {ValoperAddress: v2, Weight: sdk.NewDec(10).Quo(sdk.NewDec(50))}, {ValoperAddress: v3, Weight: sdk.NewDec(35).Quo(sdk.NewDec(50))}, @@ -108,7 +108,7 @@ func TestOrdinalizeIntentWithNonEqualIntents(t *testing.T) { func TestAddOrdinal(t *testing.T) { di := types.DelegatorIntent{ - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ {ValoperAddress: v1, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, {ValoperAddress: v2, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, @@ -135,7 +135,7 @@ func TestAddOrdinal(t *testing.T) { } func TestAddOrdinalWithNewVal(t *testing.T) { - di := types.DelegatorIntent{Delegator: utils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ + di := types.DelegatorIntent{Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ {ValoperAddress: v1, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, {ValoperAddress: v2, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, {ValoperAddress: v3, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, diff --git a/x/interchainstaking/types/zones.go b/x/interchainstaking/types/zones.go index 48038e767..aa85099a3 100644 --- a/x/interchainstaking/types/zones.go +++ b/x/interchainstaking/types/zones.go @@ -8,7 +8,7 @@ import ( "strings" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" + "github.com/ingenuity-build/quicksilver/utils/addressutils" ) func (z Zone) SupportReturnToSender() bool { return z.ReturnToSender } @@ -207,7 +207,7 @@ func (z *Zone) validatorIntentsFromBytes(coins sdk.Coins, weightBytes []byte) (V index++ address := weightBytes[index : index+20] index += 20 - valAddr, err := bech32.ConvertAndEncode(z.AccountPrefix+"valoper", address) + valAddr, err := addressutils.EncodeAddressToBech32(z.AccountPrefix+"valoper", sdk.ValAddress(address)) if err != nil { return validatorIntents, err } diff --git a/x/interchainstaking/types/zones_test.go b/x/interchainstaking/types/zones_test.go index 21143b920..c808469b6 100644 --- a/x/interchainstaking/types/zones_test.go +++ b/x/interchainstaking/types/zones_test.go @@ -8,25 +8,25 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) func TestIsDelegateAddress(t *testing.T) { - acc := utils.GenerateAccAddressForTest() - acc2 := utils.GenerateAccAddressForTest() - bech32 := utils.ConvertAccAddressForTestUsingPrefix(acc, "cosmos") - bech322 := utils.ConvertAccAddressForTestUsingPrefix(acc2, "cosmos") + acc := addressutils.GenerateAccAddressForTest() + acc2 := addressutils.GenerateAccAddressForTest() + bech32 := addressutils.MustEncodeAddressToBech32("cosmos", acc) + bech322 := addressutils.MustEncodeAddressToBech32("cosmos", acc2) zone := types.Zone{ConnectionId: "connection-0", ChainId: "cosmoshub-4", AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom", DelegationAddress: &types.ICAAccount{Address: bech32}, Is_118: true} require.True(t, zone.IsDelegateAddress(bech32)) require.False(t, zone.IsDelegateAddress(bech322)) } func TestGetDelegationAccount(t *testing.T) { - acc := utils.GenerateAccAddressForTest() - bech32 := utils.ConvertAccAddressForTestUsingPrefix(acc, "cosmos") + acc := addressutils.GenerateAccAddressForTest() + bech32 := addressutils.MustEncodeAddressToBech32("cosmos", acc) zone := types.Zone{ConnectionId: "connection-0", ChainId: "cosmoshub-4", AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom", DelegationAddress: &types.ICAAccount{Address: bech32}, Is_118: true} - zone2 := types.Zone{ConnectionId: "connection-0", ChainId: "cosmoshub-4", AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom", Is_118: true} + zone2 := types.Zone{ConnectionId: "connection-0", ChainId: "cosmoshub-4", AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom"} delegateAccount, err := zone.GetDelegationAccount() require.NoError(t, err) @@ -412,7 +412,7 @@ func TestUpdateIntentWithCoins(t *testing.T) { func intentFromDecSlice(in map[string]sdk.Dec) types.DelegatorIntent { out := types.DelegatorIntent{ - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{}, } for addr, weight := range in { diff --git a/x/participationrewards/keeper/distribution.go b/x/participationrewards/keeper/distribution.go index 1ec386d14..bd7096def 100644 --- a/x/participationrewards/keeper/distribution.go +++ b/x/participationrewards/keeper/distribution.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ingenuity-build/quicksilver/internal/multierror" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) @@ -187,7 +187,7 @@ func (k *Keeper) DistributeToUsers(ctx sdk.Context, userAllocations []types.User ), ) - addrBytes, err := utils.AccAddressFromBech32(ua.Address, "") + addrBytes, err := addressutils.AccAddressFromBech32(ua.Address, "") if err != nil { k.Logger(ctx).Error("unmarshalling address", "address", ua.Address) hasError = true diff --git a/x/participationrewards/keeper/keeper_test.go b/x/participationrewards/keeper/keeper_test.go index 85aa8684c..e89436e97 100644 --- a/x/participationrewards/keeper/keeper_test.go +++ b/x/participationrewards/keeper/keeper_test.go @@ -10,7 +10,6 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -19,7 +18,7 @@ import ( ibctesting "github.com/cosmos/ibc-go/v5/testing" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" epochtypes "github.com/ingenuity-build/quicksilver/x/epochs/types" ics "github.com/ingenuity-build/quicksilver/x/interchainstaking" @@ -27,7 +26,7 @@ import ( "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -var testAddress = utils.GenerateAccAddressForTest().String() +var testAddress = addressutils.GenerateAddressForTestWithPrefix("cosmos") func init() { ibctesting.DefaultTestingAppInit = app.SetupTestingApp @@ -186,10 +185,10 @@ func (suite *KeeperTestSuite) setupTestZones() { } // self zone - performanceAddressOsmo := utils.GenerateAccAddressForTestWithPrefix("osmo") + performanceAddressOsmo := addressutils.GenerateAddressForTestWithPrefix("osmo") performanceAccountOsmo, err := icstypes.NewICAAccount(performanceAddressOsmo, "self") suite.Require().NoError(err) - performanceAccountOsmo.WithdrawalAddress = utils.GenerateAccAddressForTestWithPrefix("osmo") + performanceAccountOsmo.WithdrawalAddress = addressutils.GenerateAddressForTestWithPrefix("osmo") zoneSelf := icstypes.Zone{ ConnectionId: "connection-77004", @@ -231,10 +230,10 @@ func (suite *KeeperTestSuite) setupTestZones() { quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zoneSelf) // cosmos zone - performanceAddressCosmos := utils.GenerateAccAddressForTestWithPrefix("cosmos") + performanceAddressCosmos := addressutils.GenerateAddressForTestWithPrefix("cosmos") performanceAccountCosmos, err := icstypes.NewICAAccount(performanceAddressCosmos, "cosmoshub-4.performance") suite.Require().NoError(err) - performanceAccountCosmos.WithdrawalAddress = utils.GenerateAccAddressForTestWithPrefix("cosmos") + performanceAccountCosmos.WithdrawalAddress = addressutils.GenerateAddressForTestWithPrefix("cosmos") zoneCosmos := icstypes.Zone{ ConnectionId: "connection-77001", @@ -285,9 +284,9 @@ func (suite *KeeperTestSuite) setupTestZones() { ReturnToSender: false, LiquidityModule: true, PerformanceAddress: &icstypes.ICAAccount{ - Address: utils.GenerateAccAddressForTestWithPrefix("osmo"), + Address: addressutils.GenerateAddressForTestWithPrefix("osmo"), PortName: "cosmoshub-4.performance", - WithdrawalAddress: utils.GenerateAccAddressForTestWithPrefix("osmo"), + WithdrawalAddress: addressutils.GenerateAddressForTestWithPrefix("osmo"), }, Is_118: true, } @@ -343,10 +342,7 @@ func (suite *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountS return err } - addr, err := bech32.ConvertAndEncode(remotePrefix, utils.GenerateAccAddressForTest()) - if err != nil { - return err - } + addr := addressutils.GenerateAddressForTestWithPrefix(remotePrefix) quicksilver.ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), connectionID, portID, addr) return ibcModule.OnChanOpenAck(suite.chainA.GetContext(), portID, channelID, "", "") } @@ -473,8 +469,8 @@ func (suite *KeeperTestSuite) addReceipt(zone *icstypes.Zone, sender, hash strin suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetReceipt(suite.chainA.GetContext(), receipt) - delegationAddress := utils.GenerateAccAddressForTestWithPrefix("cosmos") - validatorAddress := utils.GenerateValAddressForTestWithPrefix("cosmos") + delegationAddress := addressutils.GenerateAddressForTestWithPrefix("cosmos") + validatorAddress := addressutils.GenerateAddressForTestWithPrefix("cosmos") delegation := icstypes.Delegation{ DelegationAddress: delegationAddress, ValidatorAddress: validatorAddress, diff --git a/x/participationrewards/keeper/msg_server_test.go b/x/participationrewards/keeper/msg_server_test.go index 54e0ebfa7..d598622ee 100644 --- a/x/participationrewards/keeper/msg_server_test.go +++ b/x/participationrewards/keeper/msg_server_test.go @@ -14,6 +14,7 @@ import ( "github.com/ingenuity-build/quicksilver/app" osmolockup "github.com/ingenuity-build/quicksilver/osmosis-types/lockup" "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/keeper" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" @@ -40,7 +41,7 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { "invalid_height", func() { msg = types.MsgSubmitClaim{ - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), Zone: suite.chainB.ChainID, SrcZone: suite.chainB.ChainID, ClaimType: cmtypes.ClaimTypeOsmosisPool, @@ -61,8 +62,8 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { { "invalid_osmosis_user", func() { - userAddress := utils.GenerateAccAddressForTest() - osmoAddress := utils.GenerateAccAddressForTestWithPrefix("osmo") + userAddress := addressutils.GenerateAccAddressForTest() + osmoAddress := addressutils.GenerateAddressForTestWithPrefix("osmo") lockedResp := osmolockup.LockedResponse{ Lock: &osmolockup.PeriodLock{ ID: 1, @@ -101,8 +102,8 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { { "invalid_osmosis_pool", func() { - userAddress := utils.GenerateAccAddressForTest() - osmoAddress := utils.ConvertAccAddressForTestUsingPrefix(userAddress, "osmo") + userAddress := addressutils.GenerateAccAddressForTest() + osmoAddress := addressutils.MustEncodeAddressToBech32("osmo", userAddress) lockedResp := osmolockup.LockedResponse{ Lock: &osmolockup.PeriodLock{ ID: 1, @@ -141,8 +142,8 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { { "valid_osmosis", func() { - userAddress := utils.GenerateAccAddressForTest() - osmoAddress := utils.ConvertAccAddressForTestUsingPrefix(userAddress, "osmo") + userAddress := addressutils.GenerateAccAddressForTest() + osmoAddress := addressutils.MustEncodeAddressToBech32("osmo", userAddress) locked := &osmolockup.PeriodLock{ ID: 1, Owner: osmoAddress, @@ -179,7 +180,7 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { { "valid_liquid", func() { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3")) cd := sdk.Coin{ @@ -211,7 +212,7 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { { "valid_liquid", func() { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3")) cd := sdk.Coin{ @@ -268,7 +269,7 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { } func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() var msg *types.MsgSubmitClaim tests := []struct { @@ -283,7 +284,7 @@ func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { "local_callback_nil", func(ctx sdk.Context, appA *app.Quicksilver) {}, func(ctx sdk.Context, appA *app.Quicksilver) *types.MsgSubmitClaim { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3")) query := abci.RequestQuery{ diff --git a/x/participationrewards/keeper/rewards_holdings_test.go b/x/participationrewards/keeper/rewards_holdings_test.go index afbc03359..dc70d95cd 100644 --- a/x/participationrewards/keeper/rewards_holdings_test.go +++ b/x/participationrewards/keeper/rewards_holdings_test.go @@ -5,14 +5,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { - user1 := utils.GenerateAccAddressForTest() - user2 := utils.GenerateAccAddressForTest() + user1 := addressutils.GenerateAccAddressForTest() + user2 := addressutils.GenerateAccAddressForTest() tests := []struct { name string diff --git a/x/participationrewards/types/msgs_test.go b/x/participationrewards/types/msgs_test.go index 9b69ce951..1637935d0 100644 --- a/x/participationrewards/types/msgs_test.go +++ b/x/participationrewards/types/msgs_test.go @@ -9,13 +9,13 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/proto/tendermint/crypto" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) func TestMsgSubmitClaim_ValidateBasic(t *testing.T) { - userAddress := utils.GenerateAccAddressForTest().String() + userAddress := addressutils.GenerateAccAddressForTest().String() type fields struct { UserAddress string @@ -106,7 +106,7 @@ func TestMsgSubmitClaim_ValidateBasic(t *testing.T) { } func TestMsgSubmitClaim_GetSigners(t *testing.T) { - validAddress := utils.GenerateAccAddressForTest().String() + validAddress := addressutils.GenerateAccAddressForTest().String() validAcc, _ := sdk.AccAddressFromBech32(validAddress) type fields struct { @@ -150,7 +150,7 @@ func TestMsgSubmitClaim_GetSigners(t *testing.T) { } func TestNewMsgSubmitClaim(t *testing.T) { - userAddress := utils.GenerateAccAddressForTest() + userAddress := addressutils.GenerateAccAddressForTest() type args struct { userAddress sdk.Address srcZone string From a8333ed99d6290439787bdc701531b7b4b2a5782 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Thu, 8 Jun 2023 01:36:25 +0100 Subject: [PATCH 15/25] add test for randomutils --- utils/randomutils/random_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 utils/randomutils/random_test.go diff --git a/utils/randomutils/random_test.go b/utils/randomutils/random_test.go new file mode 100644 index 000000000..e381b3122 --- /dev/null +++ b/utils/randomutils/random_test.go @@ -0,0 +1,23 @@ +package randomutils_test + +import ( + "encoding/hex" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/ingenuity-build/quicksilver/utils/randomutils" +) + +func TestGenerateRandomHash(t *testing.T) { + var byteslice []byte = randomutils.GenerateRandomHash() + require.Equal(t, 32, len(byteslice)) +} + +func TestGenerateRandomHashAsHex(t *testing.T) { + var hexHash string = randomutils.GenerateRandomHashAsHex() + require.Equal(t, 64, len(hexHash)) + byteslice, err := hex.DecodeString(hexHash) + require.NoError(t, err) + require.Equal(t, 32, len(byteslice)) +} From 08c63820465d00a56085945d44f3e11000b5f395 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Thu, 8 Jun 2023 01:41:48 +0100 Subject: [PATCH 16/25] fix: remove potential non-det by iterating over maps using sorted keys --- osmosis-types/validation.go | 5 +++-- x/participationrewards/keeper/distribution.go | 9 +++++---- x/participationrewards/types/submodule_osmosis.go | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/osmosis-types/validation.go b/osmosis-types/validation.go index c5110e7d7..333c276bb 100644 --- a/osmosis-types/validation.go +++ b/osmosis-types/validation.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" osmosislockuptypes "github.com/ingenuity-build/quicksilver/osmosis-types/lockup" + "github.com/ingenuity-build/quicksilver/utils" participationrewardstypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) @@ -34,8 +35,8 @@ func DetermineApplicableTokensInPool(ctx sdk.Context, prKeeper ParticipationRewa pool, _ := ipool.(*participationrewardstypes.OsmosisPoolProtocolData) poolDenom := "" - for zk, zd := range pool.Denoms { - if zd.ChainID == chainID { + for _, zk := range utils.Keys(pool.Denoms) { + if pool.Denoms[zk].ChainID == chainID { poolDenom = zk break } diff --git a/x/participationrewards/keeper/distribution.go b/x/participationrewards/keeper/distribution.go index bd7096def..bcd40120b 100644 --- a/x/participationrewards/keeper/distribution.go +++ b/x/participationrewards/keeper/distribution.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ingenuity-build/quicksilver/internal/multierror" + "github.com/ingenuity-build/quicksilver/utils" "github.com/ingenuity-build/quicksilver/utils/addressutils" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" @@ -58,18 +59,18 @@ func (k *Keeper) CalcTokenValues(ctx sdk.Context) (TokenValues, error) { var baseIBCDenom, queryIBCDenom, valueDenom string isBasePair := false - for ibcDenom, denom := range pool.Denoms { - if denom.ChainID == baseChain { + for _, ibcDenom := range utils.Keys(pool.Denoms) { + if pool.Denoms[ibcDenom].ChainID == baseChain { isBasePair = true baseIBCDenom = ibcDenom } else { - zone, ok := k.icsKeeper.GetZone(ctx, denom.ChainID) + zone, ok := k.icsKeeper.GetZone(ctx, pool.Denoms[ibcDenom].ChainID) if !ok { // errs[idxLabel] = fmt.Errorf("zone not found, %s", denom.ChainId) return false } - if denom.Denom == zone.BaseDenom { + if pool.Denoms[ibcDenom].Denom == zone.BaseDenom { queryIBCDenom = ibcDenom valueDenom = zone.BaseDenom } else { diff --git a/x/participationrewards/types/submodule_osmosis.go b/x/participationrewards/types/submodule_osmosis.go index be379b9bd..64a5423c7 100644 --- a/x/participationrewards/types/submodule_osmosis.go +++ b/x/participationrewards/types/submodule_osmosis.go @@ -11,6 +11,7 @@ import ( "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/balancer" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/stableswap" + "github.com/ingenuity-build/quicksilver/utils" ) const ( @@ -89,14 +90,14 @@ func (opd *OsmosisPoolProtocolData) ValidateBasic() error { } i := 0 - for ibcdenom, denom := range opd.Denoms { + for _, ibcdenom := range utils.Keys(opd.Denoms) { el := fmt.Sprintf("Denoms[%s]", ibcdenom) - if denom.ChainID == "" || len(strings.Split(denom.ChainID, "-")) < 2 { + if opd.Denoms[ibcdenom].ChainID == "" || len(strings.Split(opd.Denoms[ibcdenom].ChainID, "-")) < 2 { errs[el+" key"] = fmt.Errorf("%w, chainID", ErrInvalidChainID) } - if denom.Denom == "" || sdk.ValidateDenom(denom.Denom) != nil { + if opd.Denoms[ibcdenom].Denom == "" || sdk.ValidateDenom(opd.Denoms[ibcdenom].Denom) != nil { errs[el+" value"] = fmt.Errorf("%w, IBC/denom", ErrInvalidDenom) } From a8bc5eb86906d3d14d2c9232499f7fab87144374 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Thu, 8 Jun 2023 15:41:23 +0100 Subject: [PATCH 17/25] resolve outstanding nits --- .../interchainstaking/v1/proposals.proto | 78 +++--- utils/addressutils/address.go | 4 +- utils/randomutils/random.go | 25 +- utils/randomutils/random_test.go | 10 +- .../keeper/address_map_test.go | 22 +- x/interchainstaking/keeper/grpc_query.go | 4 +- x/interchainstaking/keeper/grpc_query_test.go | 11 +- x/interchainstaking/keeper/keeper_test.go | 35 +-- .../keeper/proposal_handler.go | 1 + x/interchainstaking/keeper/receipt.go | 6 +- x/interchainstaking/keeper/receipt_test.go | 22 +- x/interchainstaking/types/proposals.pb.go | 191 ++++++++----- x/participationrewards/types/params.go | 16 -- .../types/participationrewards.pb.go | 254 +++--------------- 14 files changed, 283 insertions(+), 396 deletions(-) diff --git a/proto/quicksilver/interchainstaking/v1/proposals.proto b/proto/quicksilver/interchainstaking/v1/proposals.proto index 9180f8656..730dbad90 100644 --- a/proto/quicksilver/interchainstaking/v1/proposals.proto +++ b/proto/quicksilver/interchainstaking/v1/proposals.proto @@ -14,10 +14,11 @@ message RegisterZoneProposal { string title = 1; string description = 2; - string connection_id = 3 [(gogoproto.moretags) = "yaml:\"connection_id\""]; - string base_denom = 4 [(gogoproto.moretags) = "yaml:\"base_denom\""]; - string local_denom = 5 [(gogoproto.moretags) = "yaml:\"local_denom\""]; - string account_prefix = 6 [(gogoproto.moretags) = "yaml:\"account_prefix\""]; + string connection_id = 3 [ (gogoproto.moretags) = "yaml:\"connection_id\"" ]; + string base_denom = 4 [ (gogoproto.moretags) = "yaml:\"base_denom\"" ]; + string local_denom = 5 [ (gogoproto.moretags) = "yaml:\"local_denom\"" ]; + string account_prefix = 6 + [ (gogoproto.moretags) = "yaml:\"account_prefix\"" ]; bool multi_send = 7; // deprecated bool liquidity_module = 8; int64 messages_per_tx = 9; @@ -25,26 +26,33 @@ message RegisterZoneProposal { bool deposits_enabled = 11; bool unbonding_enabled = 12; int64 decimals = 13; + bool is_118 = 14; } message RegisterZoneProposalWithDeposit { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - string title = 1 [(gogoproto.moretags) = "yaml:\"title\""]; - string description = 2 [(gogoproto.moretags) = "yaml:\"description\""]; - string connection_id = 3 [(gogoproto.moretags) = "yaml:\"connection_id\""]; - string base_denom = 4 [(gogoproto.moretags) = "yaml:\"base_denom\""]; - string local_denom = 5 [(gogoproto.moretags) = "yaml:\"local_denom\""]; - string account_prefix = 6 [(gogoproto.moretags) = "yaml:\"account_prefix\""]; - bool multi_send = 7 [(gogoproto.moretags) = "yaml:\"multi_send\""]; - bool liquidity_module = 8 [(gogoproto.moretags) = "yaml:\"liquidity_module\""]; - string deposit = 9 [(gogoproto.moretags) = "yaml:\"deposit\""]; + string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; + string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; + string connection_id = 3 [ (gogoproto.moretags) = "yaml:\"connection_id\"" ]; + string base_denom = 4 [ (gogoproto.moretags) = "yaml:\"base_denom\"" ]; + string local_denom = 5 [ (gogoproto.moretags) = "yaml:\"local_denom\"" ]; + string account_prefix = 6 + [ (gogoproto.moretags) = "yaml:\"account_prefix\"" ]; + bool multi_send = 7 [ (gogoproto.moretags) = "yaml:\"multi_send\"" ]; + bool liquidity_module = 8 + [ (gogoproto.moretags) = "yaml:\"liquidity_module\"" ]; + string deposit = 9 [ (gogoproto.moretags) = "yaml:\"deposit\"" ]; int64 messages_per_tx = 10; - bool return_to_sender = 11 [(gogoproto.moretags) = "yaml:\"return_to_sender\""]; - bool deposits_enabled = 12 [(gogoproto.moretags) = "yaml:\"deposits_enabled\""]; - bool unbonding_enabled = 13 [(gogoproto.moretags) = "yaml:\"deposits_enabled\""]; - int64 decimals = 14 [(gogoproto.moretags) = "yaml:\"decimals\""]; + bool return_to_sender = 11 + [ (gogoproto.moretags) = "yaml:\"return_to_sender\"" ]; + bool deposits_enabled = 12 + [ (gogoproto.moretags) = "yaml:\"deposits_enabled\"" ]; + bool unbonding_enabled = 13 + [ (gogoproto.moretags) = "yaml:\"deposits_enabled\"" ]; + int64 decimals = 14 [ (gogoproto.moretags) = "yaml:\"decimals\"" ]; + bool is_118 = 15; } message UpdateZoneProposal { @@ -52,30 +60,32 @@ message UpdateZoneProposal { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; - string title = 1 [(gogoproto.moretags) = "yaml:\"title\""]; - string description = 2 [(gogoproto.moretags) = "yaml:\"description\""]; - string chain_id = 3 [(gogoproto.moretags) = "yaml:\"chain_id\""]; + string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; + string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; + string chain_id = 3 [ (gogoproto.moretags) = "yaml:\"chain_id\"" ]; - repeated UpdateZoneValue changes = 4 [(gogoproto.moretags) = "yaml:\"changes\""]; + repeated UpdateZoneValue changes = 4 + [ (gogoproto.moretags) = "yaml:\"changes\"" ]; } message UpdateZoneProposalWithDeposit { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - string title = 1 [(gogoproto.moretags) = "yaml:\"title\""]; - string description = 2 [(gogoproto.moretags) = "yaml:\"description\""]; - string chain_id = 3 [(gogoproto.moretags) = "yaml:\"chain_id\""]; + string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; + string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; + string chain_id = 3 [ (gogoproto.moretags) = "yaml:\"chain_id\"" ]; - repeated UpdateZoneValue changes = 4 [(gogoproto.moretags) = "yaml:\"changes\""]; - string deposit = 5 [(gogoproto.moretags) = "yaml:\"deposit\""]; + repeated UpdateZoneValue changes = 4 + [ (gogoproto.moretags) = "yaml:\"changes\"" ]; + string deposit = 5 [ (gogoproto.moretags) = "yaml:\"deposit\"" ]; } // UpdateZoneValue defines an individual parameter change, for use in // UpdateZoneProposal. message UpdateZoneValue { - string key = 1 [(gogoproto.moretags) = "yaml:\"key\""]; - string value = 2 [(gogoproto.moretags) = "yaml:\"value\""]; + string key = 1 [ (gogoproto.moretags) = "yaml:\"key\"" ]; + string value = 2 [ (gogoproto.moretags) = "yaml:\"value\"" ]; } message MsgGovReopenChannel { @@ -85,10 +95,10 @@ message MsgGovReopenChannel { string title = 1; string description = 2; - string connection_id = 3 [(gogoproto.moretags) = "yaml:\"connection_id\""]; - string port_id = 4 [(gogoproto.moretags) = "yaml:\"port_id\""]; + string connection_id = 3 [ (gogoproto.moretags) = "yaml:\"connection_id\"" ]; + string port_id = 4 [ (gogoproto.moretags) = "yaml:\"port_id\"" ]; - string authority = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string authority = 5 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; } // MsgGovReopenChannelResponse defines the MsgGovReopenChannel response type. @@ -101,10 +111,10 @@ message MsgGovCloseChannel { string title = 1; string description = 2; - string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""]; - string port_id = 4 [(gogoproto.moretags) = "yaml:\"port_id\""]; + string channel_id = 3 [ (gogoproto.moretags) = "yaml:\"channel_id\"" ]; + string port_id = 4 [ (gogoproto.moretags) = "yaml:\"port_id\"" ]; - string authority = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string authority = 5 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; } // MsgGovCloseChannelResponse defines the MsgGovCloseChannel response type. diff --git a/utils/addressutils/address.go b/utils/addressutils/address.go index 59c304bd3..f20e1c41b 100644 --- a/utils/addressutils/address.go +++ b/utils/addressutils/address.go @@ -77,12 +77,12 @@ func MustValAddressFromBech32(address, prefix string) sdk.ValAddress { // GenerateAccAddressForTest generates a random sdk.AccAddress for test purposes. func GenerateAccAddressForTest() sdk.AccAddress { - return sdk.AccAddress(randomutils.GenerateRandomHash()) + return sdk.AccAddress(randomutils.GenerateRandomBytes(32)) } // GenerateValAddressForTest generates a random sdk.ValAddress for test purposes. func GenerateValAddressForTest() sdk.ValAddress { - return sdk.ValAddress(randomutils.GenerateRandomHash()) + return sdk.ValAddress(randomutils.GenerateRandomBytes(32)) } // GenerateAddressForTestWithPrefix generates a random bech32 address with the specified prefix for test purposes. diff --git a/utils/randomutils/random.go b/utils/randomutils/random.go index 8703b68ea..bfee503e1 100644 --- a/utils/randomutils/random.go +++ b/utils/randomutils/random.go @@ -5,30 +5,21 @@ import ( "encoding/hex" ) -func GenerateRandomHash() []byte { - bytes := make([]byte, 32) - _, err := rand.Read(bytes) - if err != nil { - panic("unable to read random bytes") - } - return bytes -} - -func GenerateRandomHashAsHex() string { - return hex.EncodeToString(GenerateRandomHash()) -} - // GenerateRandomBytes returns securely generated random bytes. -// It will return an error if the system's secure random +// It will panic if the system's secure random // number generator fails to function correctly, in which // case the caller should not continue. -func GenerateRandomBytes(n int) ([]byte, error) { +func GenerateRandomBytes(n int) []byte { b := make([]byte, n) _, err := rand.Read(b) // Note that err == nil only if we read len(b) bytes. if err != nil { - return nil, err + panic("unable to read random bytes") } - return b, nil + return b +} + +func GenerateRandomHashAsHex(n int) string { + return hex.EncodeToString(GenerateRandomBytes(n)) } diff --git a/utils/randomutils/random_test.go b/utils/randomutils/random_test.go index e381b3122..0f6e78d13 100644 --- a/utils/randomutils/random_test.go +++ b/utils/randomutils/random_test.go @@ -2,7 +2,9 @@ package randomutils_test import ( "encoding/hex" + "math/rand" "testing" + "time" "github.com/stretchr/testify/require" @@ -10,12 +12,14 @@ import ( ) func TestGenerateRandomHash(t *testing.T) { - var byteslice []byte = randomutils.GenerateRandomHash() - require.Equal(t, 32, len(byteslice)) + random := rand.New(rand.NewSource(time.Now().UnixNano())) + b := random.Intn(128) + var byteslice []byte = randomutils.GenerateRandomBytes(b) + require.Equal(t, b, len(byteslice)) } func TestGenerateRandomHashAsHex(t *testing.T) { - var hexHash string = randomutils.GenerateRandomHashAsHex() + var hexHash string = randomutils.GenerateRandomHashAsHex(32) require.Equal(t, 64, len(hexHash)) byteslice, err := hex.DecodeString(hexHash) require.NoError(t, err) diff --git a/x/interchainstaking/keeper/address_map_test.go b/x/interchainstaking/keeper/address_map_test.go index e0f7f9f5a..b9c0c8dfb 100644 --- a/x/interchainstaking/keeper/address_map_test.go +++ b/x/interchainstaking/keeper/address_map_test.go @@ -1,6 +1,8 @@ package keeper_test -import "github.com/ingenuity-build/quicksilver/utils" +import ( + "github.com/ingenuity-build/quicksilver/utils/randomutils" +) const ( testChainID = "test-1" @@ -13,10 +15,8 @@ func (s *KeeperTestSuite) TestKeeper_RemoteAddressStore() { icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper ctx := s.chainA.GetContext() - localAddress, err := utils.GenerateRandomBytes(28) - s.Require().NoError(err) - remoteAddress, err := utils.GenerateRandomBytes(40) - s.Require().NoError(err) + localAddress := randomutils.GenerateRandomBytes(28) + remoteAddress := randomutils.GenerateRandomBytes(40) s.Run("not found", func() { _, found := icsKeeper.GetRemoteAddressMap(ctx, localAddress, testChainID) @@ -41,10 +41,8 @@ func (s *KeeperTestSuite) TestKeeper_LocalAddressStore() { icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper ctx := s.chainA.GetContext() - localAddress, err := utils.GenerateRandomBytes(28) - s.Require().NoError(err) - remoteAddress, err := utils.GenerateRandomBytes(40) - s.Require().NoError(err) + localAddress := randomutils.GenerateRandomBytes(28) + remoteAddress := randomutils.GenerateRandomBytes(40) s.Run("not found", func() { _, found := icsKeeper.GetLocalAddressMap(ctx, remoteAddress, testChainID) @@ -69,10 +67,8 @@ func (s *KeeperTestSuite) TestKeeper_AddressMapPair() { icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper ctx := s.chainA.GetContext() - localAddress, err := utils.GenerateRandomBytes(28) - s.Require().NoError(err) - remoteAddress, err := utils.GenerateRandomBytes(40) - s.Require().NoError(err) + localAddress := randomutils.GenerateRandomBytes(28) + remoteAddress := randomutils.GenerateRandomBytes(40) s.Run("not found", func() { _, found := icsKeeper.GetLocalAddressMap(ctx, remoteAddress, testChainID) diff --git a/x/interchainstaking/keeper/grpc_query.go b/x/interchainstaking/keeper/grpc_query.go index 1a64c5506..615b85af7 100644 --- a/x/interchainstaking/keeper/grpc_query.go +++ b/x/interchainstaking/keeper/grpc_query.go @@ -10,7 +10,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -264,7 +264,7 @@ func (k *Keeper) MappedAccounts(c context.Context, req *types.QueryMappedAccount ctx := sdk.UnwrapSDKContext(c) remoteAddressMap := make(map[string][]byte) - addrBytes, err := utils.AccAddressFromBech32(req.Address, sdk.GetConfig().GetBech32AccountAddrPrefix()) + addrBytes, err := addressutils.AccAddressFromBech32(req.Address, sdk.GetConfig().GetBech32AccountAddrPrefix()) if err != nil { return nil, status.Error(codes.InvalidArgument, "Invalid Address") } diff --git a/x/interchainstaking/keeper/grpc_query_test.go b/x/interchainstaking/keeper/grpc_query_test.go index c7a1a1e02..3dc15ff6a 100644 --- a/x/interchainstaking/keeper/grpc_query_test.go +++ b/x/interchainstaking/keeper/grpc_query_test.go @@ -7,7 +7,8 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" + "github.com/ingenuity-build/quicksilver/utils/randomutils" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -836,7 +837,7 @@ func (suite *KeeperTestSuite) TestKeeper_RedelegationRecords() { func (s *KeeperTestSuite) TestKeeper_MappedAccounts() { icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - usrAddress1, _ := utils.AccAddressFromBech32("cosmos1vwh8mkgefn73vpsv7td68l3tynayck07engahn", "cosmos") + usrAddress1, _ := addressutils.AccAddressFromBech32("cosmos1vwh8mkgefn73vpsv7td68l3tynayck07engahn", "cosmos") ctx := s.chainA.GetContext() tests := []struct { @@ -890,7 +891,7 @@ func (s *KeeperTestSuite) TestKeeper_MappedAccounts() { } icsKeeper.SetZone(ctx, &zone) - icsKeeper.SetRemoteAddressMap(ctx, usrAddress1, utils.GenerateRandomHash(), zone.ChainId) + icsKeeper.SetRemoteAddressMap(ctx, usrAddress1, randomutils.GenerateRandomBytes(32), zone.ChainId) }, &types.QueryMappedAccountsRequest{Address: "cosmos1vwh8mkgefn73vpsv7td68l3tynayck07engahn"}, false, @@ -913,7 +914,7 @@ func (s *KeeperTestSuite) TestKeeper_MappedAccounts() { } icsKeeper.SetZone(ctx, &zone) - icsKeeper.SetRemoteAddressMap(ctx, usrAddress1, utils.GenerateRandomHash(), zone.ChainId) + icsKeeper.SetRemoteAddressMap(ctx, usrAddress1, randomutils.GenerateRandomBytes(32), zone.ChainId) zone2 := types.Zone{ ConnectionId: "connection-77891", @@ -927,7 +928,7 @@ func (s *KeeperTestSuite) TestKeeper_MappedAccounts() { } icsKeeper.SetZone(ctx, &zone2) - icsKeeper.SetRemoteAddressMap(ctx, usrAddress1, utils.GenerateRandomHash(), zone2.ChainId) + icsKeeper.SetRemoteAddressMap(ctx, usrAddress1, randomutils.GenerateRandomBytes(32), zone2.ChainId) }, &types.QueryMappedAccountsRequest{Address: "cosmos1vwh8mkgefn73vpsv7td68l3tynayck07engahn"}, false, diff --git a/x/interchainstaking/keeper/keeper_test.go b/x/interchainstaking/keeper/keeper_test.go index 088a4705c..11f7f5131 100644 --- a/x/interchainstaking/keeper/keeper_test.go +++ b/x/interchainstaking/keeper/keeper_test.go @@ -87,6 +87,7 @@ func (suite *KeeperTestSuite) setupTestZones() { LiquidityModule: true, DepositsEnabled: true, Decimals: 6, + Is_118: true, } quicksilver := suite.GetQuicksilverApp(suite.chainA) @@ -274,7 +275,7 @@ func (suite *KeeperTestSuite) TestGetUnbondingAmount() { name: "one unbonding withdrawal", records: func(zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}) return out }, expected: math.NewInt(3000000), @@ -283,7 +284,7 @@ func (suite *KeeperTestSuite) TestGetUnbondingAmount() { name: "one non-unbonding withdrawal", records: func(zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusQueued, Txhash: randomutils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusQueued, Txhash: randomutils.GenerateRandomHashAsHex(64)}) return out }, expected: math.ZeroInt(), @@ -293,9 +294,9 @@ func (suite *KeeperTestSuite) TestGetUnbondingAmount() { records: func(zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) out = append(out, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}, ) return out }, @@ -306,9 +307,9 @@ func (suite *KeeperTestSuite) TestGetUnbondingAmount() { records: func(zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) out = append(out, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusQueued, Txhash: randomutils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusCompleted, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusQueued, Txhash: randomutils.GenerateRandomHashAsHex(64)}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusCompleted, Txhash: randomutils.GenerateRandomHashAsHex(64)}, ) return out }, @@ -378,7 +379,7 @@ func (suite *KeeperTestSuite) TestGetRatio() { name: "one withdrawal, no delegation, expect 1.0", records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}) return out }, delegations: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.Delegation { @@ -392,7 +393,7 @@ func (suite *KeeperTestSuite) TestGetRatio() { name: "one withdrawals, one delegation, one unbonding, expect 1.0", records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}) return out }, delegations: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.Delegation { @@ -408,7 +409,7 @@ func (suite *KeeperTestSuite) TestGetRatio() { name: "one non-unbond withdrawals, one delegation, one unbonding, expect 1.0", records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusCompleted, Txhash: randomutils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusCompleted, Txhash: randomutils.GenerateRandomHashAsHex(64)}) return out }, delegations: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.Delegation { @@ -425,9 +426,9 @@ func (suite *KeeperTestSuite) TestGetRatio() { records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) out = append(out, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(10000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}, ) return out }, @@ -445,8 +446,8 @@ func (suite *KeeperTestSuite) TestGetRatio() { records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) out = append(out, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, - icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}, + icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1500000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}, ) return out }, @@ -463,7 +464,7 @@ func (suite *KeeperTestSuite) TestGetRatio() { name: "multi unbonding withdrawal, delegation, gt 1.0", records: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord { out := make([]icstypes.WithdrawalRecord, 0) - out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex()}) + out = append(out, icstypes.WithdrawalRecord{ChainId: zone.ChainId, Delegator: zone.DelegationAddress.Address, Recipient: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(3000000))), Status: icskeeper.WithdrawStatusUnbond, Txhash: randomutils.GenerateRandomHashAsHex(64)}) return out }, delegations: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.Delegation { diff --git a/x/interchainstaking/keeper/proposal_handler.go b/x/interchainstaking/keeper/proposal_handler.go index 8f2127ac7..77e63455d 100644 --- a/x/interchainstaking/keeper/proposal_handler.go +++ b/x/interchainstaking/keeper/proposal_handler.go @@ -64,6 +64,7 @@ func (k *Keeper) HandleRegisterZoneProposal(ctx sdk.Context, p *types.RegisterZo Decimals: p.Decimals, UnbondingPeriod: int64(tmClientState.UnbondingPeriod), MessagesPerTx: p.MessagesPerTx, + Is_118: p.Is_118, } k.SetZone(ctx, zone) diff --git a/x/interchainstaking/keeper/receipt.go b/x/interchainstaking/keeper/receipt.go index 37da5562c..3d0d9026d 100644 --- a/x/interchainstaking/keeper/receipt.go +++ b/x/interchainstaking/keeper/receipt.go @@ -8,7 +8,6 @@ import ( sdkioerrors "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/cosmos/cosmos-sdk/types/tx" bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" @@ -66,11 +65,10 @@ func (k Keeper) HandleReceiptTransaction(ctx sdk.Context, txn *tx.Tx, txHash str k.NilReceipt(ctx, &zone, hash) // nil receipt will stop this hash being submitted again return nil } - // sdk.AccAddressFromBech32 doesn't work here as it expects the local HRP - _, addressBytes, err := bech32.DecodeAndConvert(senderAddress) + addressBytes, err := addressutils.AccAddressFromBech32(senderAddress, zone.GetAccountPrefix()) if err != nil { - k.Logger(ctx).Error("unable to decode sender address. Ignoring.", "senderAddress", senderAddress) + k.Logger(ctx).Error("unable to decode sender address. Ignoring.", "senderAddress", senderAddress, "error", err) k.NilReceipt(ctx, &zone, hash) // nil receipt will stop this hash being submitted again return nil } diff --git a/x/interchainstaking/keeper/receipt_test.go b/x/interchainstaking/keeper/receipt_test.go index 462ef088d..b43f24cd9 100644 --- a/x/interchainstaking/keeper/receipt_test.go +++ b/x/interchainstaking/keeper/receipt_test.go @@ -32,8 +32,8 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionGood() { suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} - hash := randomutils.GenerateRandomHashAsHex() - hash2 := randomutils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex(64) + hash2 := randomutils.GenerateRandomHashAsHex(64) before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -70,7 +70,7 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadRecipient() { suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} - hash := randomutils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex(64) before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -102,7 +102,7 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMessageType() { suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} - hash := randomutils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex(64) before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -138,7 +138,7 @@ func (suite *KeeperTestSuite) TestHandleReceiptMixedMessageTypeGood() { suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} - hash := randomutils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex(64) before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -172,7 +172,7 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMixedSender() { // suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} - hash := randomutils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex(64) before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -204,7 +204,7 @@ func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadDenom() { suite.Require().NoError(err) transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} - hash := randomutils.GenerateRandomHashAsHex() + hash := randomutils.GenerateRandomHashAsHex(64) before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) @@ -233,10 +233,10 @@ func (suite *KeeperTestSuite) TestReceiptStore() { account1 := addressutils.GenerateAccAddressForTest() account2 := addressutils.GenerateAccAddressForTest() - hash1 := randomutils.GenerateRandomHashAsHex() - hash2 := randomutils.GenerateRandomHashAsHex() - hash3 := randomutils.GenerateRandomHashAsHex() - hash4 := randomutils.GenerateRandomHashAsHex() + hash1 := randomutils.GenerateRandomHashAsHex(64) + hash2 := randomutils.GenerateRandomHashAsHex(64) + hash3 := randomutils.GenerateRandomHashAsHex(64) + hash4 := randomutils.GenerateRandomHashAsHex(64) zone2 := types.Zone{ChainId: "test-1"} diff --git a/x/interchainstaking/types/proposals.pb.go b/x/interchainstaking/types/proposals.pb.go index 9eb93fe61..0d0d90f7a 100644 --- a/x/interchainstaking/types/proposals.pb.go +++ b/x/interchainstaking/types/proposals.pb.go @@ -38,6 +38,7 @@ type RegisterZoneProposal struct { DepositsEnabled bool `protobuf:"varint,11,opt,name=deposits_enabled,json=depositsEnabled,proto3" json:"deposits_enabled,omitempty"` UnbondingEnabled bool `protobuf:"varint,12,opt,name=unbonding_enabled,json=unbondingEnabled,proto3" json:"unbonding_enabled,omitempty"` Decimals int64 `protobuf:"varint,13,opt,name=decimals,proto3" json:"decimals,omitempty"` + Is_118 bool `protobuf:"varint,14,opt,name=is_118,json=is118,proto3" json:"is_118,omitempty"` } func (m *RegisterZoneProposal) Reset() { *m = RegisterZoneProposal{} } @@ -87,6 +88,7 @@ type RegisterZoneProposalWithDeposit struct { DepositsEnabled bool `protobuf:"varint,12,opt,name=deposits_enabled,json=depositsEnabled,proto3" json:"deposits_enabled,omitempty" yaml:"deposits_enabled"` UnbondingEnabled bool `protobuf:"varint,13,opt,name=unbonding_enabled,json=unbondingEnabled,proto3" json:"unbonding_enabled,omitempty" yaml:"deposits_enabled"` Decimals int64 `protobuf:"varint,14,opt,name=decimals,proto3" json:"decimals,omitempty" yaml:"decimals"` + Is_118 bool `protobuf:"varint,15,opt,name=is_118,json=is118,proto3" json:"is_118,omitempty"` } func (m *RegisterZoneProposalWithDeposit) Reset() { *m = RegisterZoneProposalWithDeposit{} } @@ -429,68 +431,69 @@ func init() { } var fileDescriptor_04d034c830a7acfe = []byte{ - // 963 bytes of a gzipped FileDescriptorProto + // 983 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x56, 0x4f, 0x6f, 0xe3, 0xc4, - 0x1b, 0x4e, 0xfa, 0x37, 0x99, 0xfc, 0x69, 0x77, 0x36, 0xfb, 0xfb, 0x79, 0xbb, 0x34, 0x8e, 0xe6, - 0xb0, 0x0a, 0x5a, 0x36, 0xa1, 0x50, 0x01, 0x5a, 0x09, 0x69, 0xc9, 0xfe, 0x81, 0x1e, 0x56, 0xaa, - 0xdc, 0x05, 0xa4, 0x72, 0xb0, 0x1c, 0xfb, 0xc5, 0x19, 0xd5, 0x99, 0xf1, 0x7a, 0xc6, 0x51, 0xf3, - 0x0d, 0xf6, 0xc8, 0x05, 0x89, 0x63, 0x3f, 0x04, 0x1f, 0x02, 0x71, 0x5a, 0x71, 0x42, 0x02, 0x45, - 0xa8, 0xbd, 0x70, 0x25, 0x57, 0x2e, 0xc8, 0x33, 0x76, 0xe3, 0x26, 0x41, 0x3d, 0x20, 0x16, 0x24, - 0x6e, 0xf3, 0x3e, 0xcf, 0xfb, 0xbe, 0x33, 0x7e, 0xfc, 0xbc, 0xf6, 0xa0, 0xb7, 0x5f, 0xc4, 0xd4, - 0x3d, 0x11, 0x34, 0x18, 0x41, 0xd4, 0xa5, 0x4c, 0x42, 0xe4, 0x0e, 0x1c, 0xca, 0x84, 0x74, 0x4e, - 0x28, 0xf3, 0xbb, 0xa3, 0xbd, 0x6e, 0x18, 0xf1, 0x90, 0x0b, 0x27, 0x10, 0x9d, 0x30, 0xe2, 0x92, - 0xe3, 0x56, 0xae, 0xa2, 0xb3, 0x50, 0xd1, 0x19, 0xed, 0xed, 0xdc, 0x76, 0xb9, 0x18, 0x72, 0x61, - 0xab, 0xfc, 0xae, 0x0e, 0x74, 0xf1, 0x4e, 0xc3, 0xe7, 0x3e, 0xd7, 0x78, 0xb2, 0xd2, 0x28, 0xf9, - 0x79, 0x0d, 0x35, 0x2c, 0xf0, 0xa9, 0x90, 0x10, 0x1d, 0x73, 0x06, 0x87, 0xe9, 0x96, 0xb8, 0x81, - 0xd6, 0x25, 0x95, 0x01, 0x18, 0xc5, 0x56, 0xb1, 0x5d, 0xb6, 0x74, 0x80, 0x5b, 0xa8, 0xe2, 0x81, - 0x70, 0x23, 0x1a, 0x4a, 0xca, 0x99, 0xb1, 0xa2, 0xb8, 0x3c, 0x84, 0x3f, 0x44, 0x35, 0x97, 0x33, - 0x06, 0x6e, 0x12, 0xd9, 0xd4, 0x33, 0x56, 0x93, 0x9c, 0x9e, 0x31, 0x9d, 0x98, 0x8d, 0xb1, 0x33, - 0x0c, 0x1e, 0x90, 0x2b, 0x34, 0xb1, 0xaa, 0xb3, 0xf8, 0xc0, 0xc3, 0xfb, 0x08, 0xf5, 0x1d, 0x01, - 0xb6, 0x07, 0x8c, 0x0f, 0x8d, 0x35, 0x55, 0x7b, 0x6b, 0x3a, 0x31, 0x6f, 0xe8, 0xda, 0x19, 0x47, - 0xac, 0x72, 0x12, 0x3c, 0x4e, 0xd6, 0xf8, 0x7d, 0x54, 0x09, 0xb8, 0xeb, 0x04, 0x69, 0xd9, 0xba, - 0x2a, 0xfb, 0xdf, 0x74, 0x62, 0x62, 0x5d, 0x96, 0x23, 0x89, 0x85, 0x54, 0xa4, 0x0b, 0x1f, 0xa2, - 0xba, 0xe3, 0xba, 0x3c, 0x66, 0xd2, 0x0e, 0x23, 0xf8, 0x92, 0x9e, 0x1a, 0x1b, 0xaa, 0xf6, 0xf6, - 0x74, 0x62, 0xde, 0xd2, 0xb5, 0x57, 0x79, 0x62, 0xd5, 0x52, 0xe0, 0x50, 0xc5, 0x78, 0x17, 0xa1, - 0x61, 0x1c, 0x48, 0x6a, 0x0b, 0x60, 0x9e, 0xb1, 0xd9, 0x2a, 0xb6, 0x4b, 0x56, 0x59, 0x21, 0x47, - 0xc0, 0x3c, 0xfc, 0x26, 0xda, 0x0e, 0xe8, 0x8b, 0x98, 0x7a, 0x54, 0x8e, 0xed, 0x21, 0xf7, 0xe2, - 0x00, 0x8c, 0x92, 0x4a, 0xda, 0xba, 0xc4, 0x9f, 0x29, 0x18, 0xdf, 0x45, 0x5b, 0x43, 0x10, 0xc2, - 0xf1, 0x41, 0xd8, 0x21, 0x44, 0xb6, 0x3c, 0x35, 0xca, 0xad, 0x62, 0x7b, 0xd5, 0xaa, 0x65, 0xf0, - 0x21, 0x44, 0xcf, 0x4f, 0x71, 0x1b, 0x6d, 0x47, 0x20, 0xe3, 0x88, 0xd9, 0x92, 0xab, 0x5d, 0x21, - 0x32, 0x90, 0x6a, 0x59, 0xd7, 0xf8, 0x73, 0x7e, 0xa4, 0xd0, 0x64, 0x73, 0x0f, 0x42, 0x2e, 0xa8, - 0x14, 0x36, 0x30, 0xa7, 0x1f, 0x80, 0x67, 0x54, 0xf4, 0xe6, 0x19, 0xfe, 0x44, 0xc3, 0xf8, 0x1e, - 0xba, 0x11, 0xb3, 0x3e, 0x67, 0x1e, 0x65, 0xfe, 0x65, 0x6e, 0x55, 0xe5, 0x6e, 0x5f, 0x12, 0x59, - 0xf2, 0x0e, 0x2a, 0x79, 0xe0, 0xd2, 0xa1, 0x13, 0x08, 0xa3, 0xa6, 0x8e, 0x78, 0x19, 0x3f, 0xa8, - 0xbe, 0x3c, 0x33, 0x0b, 0xdf, 0x9c, 0x99, 0x85, 0x5f, 0xcf, 0xcc, 0x02, 0xf9, 0x69, 0x03, 0x99, - 0xcb, 0xec, 0xf5, 0x39, 0x95, 0x83, 0xc7, 0xfa, 0x08, 0xf8, 0xee, 0x15, 0xa7, 0xf5, 0xb6, 0xa7, - 0x13, 0xb3, 0xaa, 0xa5, 0x57, 0x30, 0xc9, 0xbc, 0xf7, 0xc1, 0x12, 0xef, 0xe5, 0x5f, 0x72, 0x8e, - 0x24, 0xff, 0x6d, 0x4f, 0xee, 0x2f, 0x7a, 0x32, 0x7f, 0xe0, 0x19, 0x47, 0xf2, 0x56, 0x7d, 0xfa, - 0x67, 0x56, 0xed, 0xdd, 0x99, 0x4e, 0xcc, 0xff, 0xa7, 0xa7, 0x9e, 0xcb, 0x20, 0x8b, 0x3e, 0x7e, - 0x0b, 0x6d, 0xa6, 0xee, 0x52, 0xfe, 0x2d, 0xf7, 0xf0, 0x74, 0x62, 0xd6, 0xb3, 0x77, 0xa4, 0x08, - 0x62, 0x65, 0x29, 0xcb, 0x5c, 0x8f, 0x96, 0xb9, 0xfe, 0xc9, 0x12, 0xd7, 0x57, 0xe6, 0x4f, 0x37, - 0x9f, 0x41, 0x16, 0x46, 0xe2, 0xe9, 0x92, 0x91, 0xa8, 0xce, 0xb7, 0x99, 0xcf, 0x20, 0x8b, 0xf3, - 0xf2, 0xc9, 0xb2, 0x79, 0xa9, 0x5d, 0xdf, 0x68, 0x71, 0x98, 0xba, 0xb9, 0x61, 0xaa, 0x27, 0x4f, - 0xde, 0xbb, 0x39, 0x9d, 0x98, 0x5b, 0x59, 0x03, 0xcd, 0x90, 0xdc, 0x84, 0x95, 0x5e, 0x66, 0xd3, - 0xf5, 0xf5, 0x0a, 0xc2, 0x9f, 0x86, 0x9e, 0x23, 0xe1, 0xca, 0xa7, 0xfb, 0xef, 0x1f, 0xa8, 0x0e, - 0x2a, 0xa9, 0x3f, 0xcf, 0x6c, 0x96, 0x72, 0x67, 0xce, 0x18, 0x62, 0x6d, 0xaa, 0xe5, 0x81, 0x87, - 0x6d, 0x94, 0x2c, 0x99, 0x0f, 0xc2, 0x58, 0x6b, 0xad, 0xb6, 0x2b, 0xef, 0xec, 0x75, 0xae, 0xfb, - 0x95, 0x75, 0x66, 0x0f, 0xf6, 0x99, 0x13, 0xc4, 0x90, 0x77, 0x51, 0xda, 0x4b, 0x6f, 0x90, 0xac, - 0xe6, 0xbe, 0x3a, 0xdf, 0xaf, 0xa0, 0xdd, 0x45, 0x5d, 0x5e, 0xef, 0x37, 0xe7, 0xdf, 0x26, 0x51, - 0x7e, 0x2c, 0xd7, 0xaf, 0x1d, 0xcb, 0x9c, 0xc9, 0xbe, 0x40, 0x5b, 0x73, 0xfb, 0xe0, 0x16, 0x5a, - 0x3d, 0x81, 0x71, 0xaa, 0x5d, 0x7d, 0x3a, 0x31, 0x91, 0x6e, 0x73, 0x02, 0x63, 0x62, 0x25, 0x54, - 0xa2, 0xef, 0x28, 0x49, 0x4d, 0x15, 0xcb, 0xe9, 0xab, 0x60, 0x62, 0x69, 0x9a, 0xfc, 0x5e, 0x44, - 0x37, 0x9f, 0x09, 0xff, 0x63, 0x3e, 0xb2, 0x80, 0x87, 0xc0, 0x1e, 0x0d, 0x1c, 0xc6, 0xe0, 0x1f, - 0xbb, 0x7d, 0xdc, 0x43, 0x9b, 0x21, 0x8f, 0x64, 0x52, 0xb8, 0x36, 0xaf, 0x51, 0x4a, 0x10, 0x6b, - 0x23, 0x59, 0x1d, 0x78, 0xf8, 0x3d, 0x54, 0x76, 0x62, 0x39, 0xe0, 0x11, 0x95, 0xe3, 0x54, 0x52, - 0xe3, 0x87, 0x6f, 0xef, 0x37, 0xd2, 0x5b, 0xd7, 0x47, 0x9e, 0x17, 0x81, 0x10, 0x47, 0x32, 0xa2, - 0xcc, 0xb7, 0x66, 0xa9, 0x39, 0x69, 0x77, 0xd1, 0x9d, 0x25, 0x0f, 0x6f, 0x81, 0x08, 0x39, 0x13, - 0x40, 0x7e, 0x2b, 0x22, 0xac, 0xf9, 0x47, 0x01, 0x17, 0xf0, 0x57, 0xb5, 0xd9, 0x47, 0xc8, 0xd5, - 0x2d, 0x66, 0xc2, 0xe4, 0xfe, 0x0a, 0x33, 0x8e, 0x58, 0xe5, 0x34, 0x78, 0xfd, 0x92, 0xbc, 0x81, - 0x76, 0x16, 0x1f, 0x39, 0x53, 0xa4, 0x77, 0xfc, 0xdd, 0x79, 0xb3, 0xf8, 0xea, 0xbc, 0x59, 0xfc, - 0xe5, 0xbc, 0x59, 0xfc, 0xea, 0xa2, 0x59, 0x78, 0x75, 0xd1, 0x2c, 0xfc, 0x78, 0xd1, 0x2c, 0x1c, - 0x3f, 0xf4, 0xa9, 0x1c, 0xc4, 0xfd, 0x8e, 0xcb, 0x87, 0x5d, 0xca, 0x7c, 0x60, 0x31, 0x95, 0xe3, - 0xfb, 0xfd, 0x98, 0x06, 0x5e, 0x37, 0x7f, 0xcf, 0x3e, 0x5d, 0x72, 0xd3, 0x96, 0xe3, 0x10, 0x44, - 0x7f, 0x43, 0x5d, 0x88, 0xdf, 0xfd, 0x23, 0x00, 0x00, 0xff, 0xff, 0x97, 0x4e, 0xb4, 0x0d, 0x97, - 0x0b, 0x00, 0x00, + 0x1b, 0x4e, 0xfa, 0x27, 0x4d, 0x26, 0xff, 0xba, 0xb3, 0xe9, 0xef, 0xe7, 0xed, 0xd2, 0x38, 0x9a, + 0xc3, 0x2a, 0x68, 0xd9, 0x84, 0x40, 0x05, 0xd5, 0x4a, 0x48, 0x4b, 0xf6, 0x0f, 0xf4, 0xb0, 0x52, + 0xe5, 0x2e, 0x20, 0x95, 0x83, 0xe5, 0xd8, 0x83, 0x33, 0xaa, 0x33, 0xe3, 0xf5, 0x8c, 0xa3, 0xe6, + 0x1b, 0xec, 0x91, 0x0b, 0x12, 0xc7, 0x7e, 0x08, 0x3e, 0x04, 0xe2, 0xb4, 0xe2, 0xc4, 0x29, 0x42, + 0xed, 0x85, 0x2b, 0xe6, 0xc8, 0x05, 0x79, 0xc6, 0x6e, 0xdc, 0xc4, 0xa8, 0x07, 0xc4, 0x82, 0xc4, + 0x6d, 0xde, 0xe7, 0x79, 0xdf, 0x77, 0xc6, 0xaf, 0x9f, 0xc7, 0x1e, 0xf0, 0xee, 0xcb, 0x90, 0xd8, + 0xa7, 0x9c, 0x78, 0x53, 0x1c, 0xf4, 0x09, 0x15, 0x38, 0xb0, 0xc7, 0x16, 0xa1, 0x5c, 0x58, 0xa7, + 0x84, 0xba, 0xfd, 0xe9, 0xa0, 0xef, 0x07, 0xcc, 0x67, 0xdc, 0xf2, 0x78, 0xcf, 0x0f, 0x98, 0x60, + 0xb0, 0x93, 0xa9, 0xe8, 0xad, 0x54, 0xf4, 0xa6, 0x83, 0xdd, 0x3b, 0x36, 0xe3, 0x13, 0xc6, 0x4d, + 0x99, 0xdf, 0x57, 0x81, 0x2a, 0xde, 0x6d, 0xb9, 0xcc, 0x65, 0x0a, 0x8f, 0x57, 0x0a, 0x45, 0xbf, + 0x6d, 0x80, 0x96, 0x81, 0x5d, 0xc2, 0x05, 0x0e, 0x4e, 0x18, 0xc5, 0x47, 0xc9, 0x96, 0xb0, 0x05, + 0x36, 0x05, 0x11, 0x1e, 0xd6, 0x8a, 0x9d, 0x62, 0xb7, 0x62, 0xa8, 0x00, 0x76, 0x40, 0xd5, 0xc1, + 0xdc, 0x0e, 0x88, 0x2f, 0x08, 0xa3, 0xda, 0x9a, 0xe4, 0xb2, 0x10, 0xfc, 0x08, 0xd4, 0x6d, 0x46, + 0x29, 0xb6, 0xe3, 0xc8, 0x24, 0x8e, 0xb6, 0x1e, 0xe7, 0x0c, 0xb5, 0x68, 0xae, 0xb7, 0x66, 0xd6, + 0xc4, 0x7b, 0x88, 0xae, 0xd1, 0xc8, 0xa8, 0x2d, 0xe2, 0x43, 0x07, 0xee, 0x03, 0x30, 0xb2, 0x38, + 0x36, 0x1d, 0x4c, 0xd9, 0x44, 0xdb, 0x90, 0xb5, 0x3b, 0xd1, 0x5c, 0xbf, 0xa5, 0x6a, 0x17, 0x1c, + 0x32, 0x2a, 0x71, 0xf0, 0x24, 0x5e, 0xc3, 0x0f, 0x41, 0xd5, 0x63, 0xb6, 0xe5, 0x25, 0x65, 0x9b, + 0xb2, 0xec, 0x7f, 0xd1, 0x5c, 0x87, 0xaa, 0x2c, 0x43, 0x22, 0x03, 0xc8, 0x48, 0x15, 0x3e, 0x02, + 0x0d, 0xcb, 0xb6, 0x59, 0x48, 0x85, 0xe9, 0x07, 0xf8, 0x2b, 0x72, 0xa6, 0x95, 0x64, 0xed, 0x9d, + 0x68, 0xae, 0xef, 0xa8, 0xda, 0xeb, 0x3c, 0x32, 0xea, 0x09, 0x70, 0x24, 0x63, 0xb8, 0x07, 0xc0, + 0x24, 0xf4, 0x04, 0x31, 0x39, 0xa6, 0x8e, 0xb6, 0xd5, 0x29, 0x76, 0xcb, 0x46, 0x45, 0x22, 0xc7, + 0x98, 0x3a, 0xf0, 0x6d, 0xb0, 0xed, 0x91, 0x97, 0x21, 0x71, 0x88, 0x98, 0x99, 0x13, 0xe6, 0x84, + 0x1e, 0xd6, 0xca, 0x32, 0xa9, 0x79, 0x85, 0x3f, 0x97, 0x30, 0xbc, 0x07, 0x9a, 0x13, 0xcc, 0xb9, + 0xe5, 0x62, 0x6e, 0xfa, 0x38, 0x30, 0xc5, 0x99, 0x56, 0xe9, 0x14, 0xbb, 0xeb, 0x46, 0x3d, 0x85, + 0x8f, 0x70, 0xf0, 0xe2, 0x0c, 0x76, 0xc1, 0x76, 0x80, 0x45, 0x18, 0x50, 0x53, 0x30, 0xb9, 0x2b, + 0x0e, 0x34, 0x20, 0x5b, 0x36, 0x14, 0xfe, 0x82, 0x1d, 0x4b, 0x34, 0xde, 0xdc, 0xc1, 0x3e, 0xe3, + 0x44, 0x70, 0x13, 0x53, 0x6b, 0xe4, 0x61, 0x47, 0xab, 0xaa, 0xcd, 0x53, 0xfc, 0xa9, 0x82, 0xe1, + 0x7d, 0x70, 0x2b, 0xa4, 0x23, 0x46, 0x1d, 0x42, 0xdd, 0xab, 0xdc, 0x9a, 0xcc, 0xdd, 0xbe, 0x22, + 0xd2, 0xe4, 0x5d, 0x50, 0x76, 0xb0, 0x4d, 0x26, 0x96, 0xc7, 0xb5, 0xba, 0x3c, 0xe2, 0x55, 0x0c, + 0x77, 0x40, 0x89, 0x70, 0x73, 0x30, 0x38, 0xd0, 0x1a, 0xb2, 0x7a, 0x93, 0xf0, 0xc1, 0xe0, 0xe0, + 0x61, 0xed, 0xd5, 0xb9, 0x5e, 0xf8, 0xf6, 0x5c, 0x2f, 0xfc, 0x72, 0xae, 0x17, 0x50, 0x54, 0x02, + 0x7a, 0x9e, 0xea, 0xbe, 0x20, 0x62, 0xfc, 0x44, 0x9d, 0x0c, 0xde, 0xbb, 0x26, 0xc0, 0xe1, 0x76, + 0x34, 0xd7, 0x6b, 0xea, 0x8d, 0x48, 0x18, 0xa5, 0x92, 0x3c, 0xc8, 0x91, 0x64, 0xf6, 0xdd, 0x67, + 0x48, 0xf4, 0xdf, 0x96, 0xea, 0xfe, 0xaa, 0x54, 0xb3, 0x07, 0x5e, 0x70, 0x28, 0xab, 0xe0, 0x67, + 0x7f, 0xa6, 0xe0, 0xe1, 0xdd, 0x68, 0xae, 0xff, 0x3f, 0x39, 0xf5, 0x52, 0x06, 0x5a, 0x95, 0xf7, + 0x3b, 0x60, 0x2b, 0x11, 0x9d, 0x94, 0x75, 0x65, 0x08, 0xa3, 0xb9, 0xde, 0x48, 0xdf, 0x91, 0x24, + 0x90, 0x91, 0xa6, 0xe4, 0x99, 0x01, 0xe4, 0x99, 0xe1, 0x69, 0x8e, 0x19, 0xaa, 0xcb, 0xa7, 0x5b, + 0xce, 0x40, 0x2b, 0x4e, 0x79, 0x96, 0xe3, 0x94, 0xda, 0x72, 0x9b, 0xe5, 0x0c, 0xb4, 0x6a, 0xa3, + 0x4f, 0xf3, 0x6c, 0x54, 0xbf, 0xb9, 0xd1, 0xaa, 0xc7, 0xfa, 0x19, 0x8f, 0xc5, 0x4e, 0x5a, 0x1f, + 0xde, 0x8e, 0xe6, 0x7a, 0x33, 0x6d, 0xa0, 0x18, 0x94, 0x6b, 0xbc, 0x66, 0xd6, 0x78, 0xe5, 0x57, + 0xa9, 0xe9, 0xbe, 0x59, 0x03, 0xf0, 0x33, 0xdf, 0xb1, 0x04, 0xbe, 0xf6, 0xa1, 0xff, 0xfb, 0x7d, + 0xd6, 0x03, 0x65, 0xf9, 0x9f, 0x5a, 0x58, 0x2c, 0xf3, 0x28, 0x29, 0x83, 0x8c, 0x2d, 0xb9, 0x3c, + 0x74, 0xa0, 0x09, 0xe2, 0x25, 0x75, 0x31, 0xd7, 0x36, 0x3a, 0xeb, 0xdd, 0xea, 0x7b, 0x83, 0xde, + 0x4d, 0x3f, 0xbe, 0xde, 0xe2, 0xc1, 0x3e, 0xb7, 0xbc, 0x10, 0x67, 0xc5, 0x95, 0xf4, 0x52, 0x1b, + 0xc4, 0xab, 0xa5, 0x8f, 0xd1, 0x0f, 0x6b, 0x60, 0x6f, 0x75, 0x2e, 0x6f, 0xf6, 0x53, 0xf4, 0x6f, + 0x1b, 0x51, 0xd6, 0xad, 0x9b, 0x37, 0xba, 0x35, 0x23, 0xb2, 0x2f, 0x41, 0x73, 0x69, 0x1f, 0xd8, + 0x01, 0xeb, 0xa7, 0x78, 0x96, 0xcc, 0xae, 0x11, 0xcd, 0x75, 0xa0, 0xda, 0x9c, 0xe2, 0x19, 0x32, + 0x62, 0x2a, 0x9e, 0xef, 0x34, 0x4e, 0x4d, 0x26, 0x96, 0x99, 0xaf, 0x84, 0x91, 0xa1, 0x68, 0xf4, + 0x7b, 0x11, 0xdc, 0x7e, 0xce, 0xdd, 0x4f, 0xd8, 0xd4, 0xc0, 0xcc, 0xc7, 0xf4, 0xf1, 0xd8, 0xa2, + 0x14, 0xff, 0x63, 0x77, 0x95, 0xfb, 0x60, 0xcb, 0x67, 0x81, 0x88, 0x0b, 0x37, 0x96, 0x67, 0x94, + 0x10, 0xc8, 0x28, 0xc5, 0xab, 0x43, 0x07, 0x7e, 0x00, 0x2a, 0x56, 0x28, 0xc6, 0x2c, 0x20, 0x62, + 0x96, 0x8c, 0x54, 0xfb, 0xf1, 0xbb, 0x07, 0xad, 0xe4, 0x8e, 0xf6, 0xb1, 0xe3, 0x04, 0x98, 0xf3, + 0x63, 0x11, 0x10, 0xea, 0x1a, 0x8b, 0xd4, 0xcc, 0x68, 0xf7, 0xc0, 0xdd, 0x9c, 0x87, 0x37, 0x30, + 0xf7, 0x19, 0xe5, 0x18, 0xfd, 0x5a, 0x04, 0x50, 0xf1, 0x8f, 0x3d, 0xc6, 0xf1, 0x5f, 0x9d, 0xcd, + 0x3e, 0x00, 0xb6, 0x6a, 0xb1, 0x18, 0x4c, 0xe6, 0x67, 0xb1, 0xe0, 0x90, 0x51, 0x49, 0x82, 0x37, + 0x3f, 0x92, 0xb7, 0xc0, 0xee, 0xea, 0x23, 0xa7, 0x13, 0x19, 0x9e, 0x7c, 0x7f, 0xd1, 0x2e, 0xbe, + 0xbe, 0x68, 0x17, 0x7f, 0xbe, 0x68, 0x17, 0xbf, 0xbe, 0x6c, 0x17, 0x5e, 0x5f, 0xb6, 0x0b, 0x3f, + 0x5d, 0xb6, 0x0b, 0x27, 0x8f, 0x5c, 0x22, 0xc6, 0xe1, 0xa8, 0x67, 0xb3, 0x49, 0x9f, 0x50, 0x17, + 0xd3, 0x90, 0x88, 0xd9, 0x83, 0x51, 0x48, 0x3c, 0xa7, 0x9f, 0xbd, 0x95, 0x9f, 0xe5, 0xdc, 0xcb, + 0xc5, 0xcc, 0xc7, 0x7c, 0x54, 0x92, 0xd7, 0xe7, 0xf7, 0xff, 0x08, 0x00, 0x00, 0xff, 0xff, 0x15, + 0x82, 0xe2, 0xcb, 0xc5, 0x0b, 0x00, 0x00, } func (m *RegisterZoneProposal) Marshal() (dAtA []byte, err error) { @@ -513,6 +516,16 @@ func (m *RegisterZoneProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Is_118 { + i-- + if m.Is_118 { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x70 + } if m.Decimals != 0 { i = encodeVarintProposals(dAtA, i, uint64(m.Decimals)) i-- @@ -638,6 +651,16 @@ func (m *RegisterZoneProposalWithDeposit) MarshalToSizedBuffer(dAtA []byte) (int _ = i var l int _ = l + if m.Is_118 { + i-- + if m.Is_118 { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x78 + } if m.Decimals != 0 { i = encodeVarintProposals(dAtA, i, uint64(m.Decimals)) i-- @@ -1134,6 +1157,9 @@ func (m *RegisterZoneProposal) Size() (n int) { if m.Decimals != 0 { n += 1 + sovProposals(uint64(m.Decimals)) } + if m.Is_118 { + n += 2 + } return n } @@ -1192,6 +1218,9 @@ func (m *RegisterZoneProposalWithDeposit) Size() (n int) { if m.Decimals != 0 { n += 1 + sovProposals(uint64(m.Decimals)) } + if m.Is_118 { + n += 2 + } return n } @@ -1711,6 +1740,26 @@ func (m *RegisterZoneProposal) Unmarshal(dAtA []byte) error { break } } + case 14: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Is_118", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposals + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Is_118 = bool(v != 0) default: iNdEx = preIndex skippy, err := skipProposals(dAtA[iNdEx:]) @@ -2123,6 +2172,26 @@ func (m *RegisterZoneProposalWithDeposit) Unmarshal(dAtA []byte) error { break } } + case 15: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Is_118", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposals + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Is_118 = bool(v != 0) default: iNdEx = preIndex skippy, err := skipProposals(dAtA[iNdEx:]) diff --git a/x/participationrewards/types/params.go b/x/participationrewards/types/params.go index 10ba5a856..72b1ffe73 100644 --- a/x/participationrewards/types/params.go +++ b/x/participationrewards/types/params.go @@ -58,13 +58,6 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { } } -// ParamSetPairs implements params.ParamSet. -func (p *ParamsV1) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyDistributionProportions, &p.DistributionProportions, validateDistributionProportions), - } -} - func validateDistributionProportions(i interface{}) error { dp, ok := i.(DistributionProportions) if !ok { @@ -93,12 +86,3 @@ func (p *Params) String() string { out, _ := yaml.Marshal(p) return string(out) } - -// String implements the Stringer interface. -func (p *ParamsV1) String() string { - out, err := yaml.Marshal(p) - if err != nil { - panic(err) - } - return string(out) -} diff --git a/x/participationrewards/types/participationrewards.pb.go b/x/participationrewards/types/participationrewards.pb.go index 62e9c2936..8de13c59a 100644 --- a/x/participationrewards/types/participationrewards.pb.go +++ b/x/participationrewards/types/participationrewards.pb.go @@ -108,45 +108,6 @@ func (m *DistributionProportions) XXX_DiscardUnknown() { var xxx_messageInfo_DistributionProportions proto.InternalMessageInfo -// Params holds parameters for the participationrewards module. -type ParamsV1 struct { - // distribution_proportions defines the proportions of the minted - // participation rewards; - DistributionProportions DistributionProportions `protobuf:"bytes,1,opt,name=distribution_proportions,json=distributionProportions,proto3" json:"distribution_proportions"` -} - -func (m *ParamsV1) Reset() { *m = ParamsV1{} } -func (*ParamsV1) ProtoMessage() {} -func (*ParamsV1) Descriptor() ([]byte, []int) { - return fileDescriptor_d4fb4e5bb851c124, []int{1} -} -func (m *ParamsV1) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ParamsV1) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ParamsV1.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ParamsV1) XXX_Merge(src proto.Message) { - xxx_messageInfo_ParamsV1.Merge(m, src) -} -func (m *ParamsV1) XXX_Size() int { - return m.Size() -} -func (m *ParamsV1) XXX_DiscardUnknown() { - xxx_messageInfo_ParamsV1.DiscardUnknown(m) -} - -var xxx_messageInfo_ParamsV1 proto.InternalMessageInfo - // Params holds parameters for the participationrewards module. type Params struct { // distribution_proportions defines the proportions of the minted @@ -158,7 +119,7 @@ type Params struct { func (m *Params) Reset() { *m = Params{} } func (*Params) ProtoMessage() {} func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_d4fb4e5bb851c124, []int{2} + return fileDescriptor_d4fb4e5bb851c124, []int{1} } func (m *Params) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -196,7 +157,7 @@ func (m *KeyedProtocolData) Reset() { *m = KeyedProtocolData{} } func (m *KeyedProtocolData) String() string { return proto.CompactTextString(m) } func (*KeyedProtocolData) ProtoMessage() {} func (*KeyedProtocolData) Descriptor() ([]byte, []int) { - return fileDescriptor_d4fb4e5bb851c124, []int{3} + return fileDescriptor_d4fb4e5bb851c124, []int{2} } func (m *KeyedProtocolData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -250,7 +211,7 @@ func (m *ProtocolData) Reset() { *m = ProtocolData{} } func (m *ProtocolData) String() string { return proto.CompactTextString(m) } func (*ProtocolData) ProtoMessage() {} func (*ProtocolData) Descriptor() ([]byte, []int) { - return fileDescriptor_d4fb4e5bb851c124, []int{4} + return fileDescriptor_d4fb4e5bb851c124, []int{3} } func (m *ProtocolData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -296,7 +257,6 @@ func (m *ProtocolData) GetData() encoding_json.RawMessage { func init() { proto.RegisterEnum("quicksilver.participationrewards.v1.ProtocolDataType", ProtocolDataType_name, ProtocolDataType_value) proto.RegisterType((*DistributionProportions)(nil), "quicksilver.participationrewards.v1.DistributionProportions") - proto.RegisterType((*ParamsV1)(nil), "quicksilver.participationrewards.v1.Params_v1") proto.RegisterType((*Params)(nil), "quicksilver.participationrewards.v1.Params") proto.RegisterType((*KeyedProtocolData)(nil), "quicksilver.participationrewards.v1.KeyedProtocolData") proto.RegisterType((*ProtocolData)(nil), "quicksilver.participationrewards.v1.ProtocolData") @@ -307,47 +267,46 @@ func init() { } var fileDescriptor_d4fb4e5bb851c124 = []byte{ - // 636 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x54, 0xc1, 0x4f, 0xd4, 0x4e, - 0x14, 0x6e, 0x97, 0xfe, 0x08, 0x0c, 0xf0, 0x4b, 0x19, 0x4d, 0x80, 0x15, 0xba, 0x88, 0xd1, 0x18, - 0x13, 0x5a, 0x17, 0x6f, 0x84, 0x98, 0xb8, 0xac, 0x27, 0x35, 0x92, 0x82, 0x1e, 0x4c, 0x4c, 0x33, - 0x3b, 0x33, 0x94, 0x71, 0x67, 0x67, 0x4a, 0xa7, 0x5d, 0xdc, 0x03, 0x89, 0xf1, 0xc4, 0xd1, 0x83, - 0x07, 0x8f, 0x26, 0xfe, 0x0b, 0x1e, 0xfc, 0x13, 0x38, 0x12, 0x4f, 0xc6, 0x03, 0x31, 0xf0, 0x5f, - 0x78, 0x30, 0x66, 0xda, 0x5d, 0xac, 0x6b, 0x4d, 0x38, 0x90, 0x78, 0xea, 0x9b, 0xf7, 0xbe, 0xf9, - 0xbe, 0x37, 0xfd, 0xde, 0x0c, 0xb8, 0xbb, 0x9b, 0x32, 0xdc, 0x56, 0x8c, 0x77, 0x69, 0xec, 0x45, - 0x28, 0x4e, 0x18, 0x66, 0x11, 0x4a, 0x98, 0x14, 0x31, 0xdd, 0x43, 0x31, 0x51, 0x5e, 0xb7, 0x5e, - 0x9a, 0x77, 0xa3, 0x58, 0x26, 0x12, 0x5e, 0x2b, 0xec, 0x77, 0x4b, 0x71, 0xdd, 0x7a, 0x75, 0x0e, - 0x4b, 0xd5, 0x91, 0x2a, 0xc8, 0xb6, 0x78, 0xf9, 0x22, 0xdf, 0x5f, 0xbd, 0x1c, 0xca, 0x50, 0xe6, - 0x79, 0x1d, 0xe5, 0xd9, 0xa5, 0x1f, 0x15, 0x30, 0xd3, 0x64, 0x2a, 0x89, 0x59, 0x2b, 0xd5, 0x5c, - 0x1b, 0xb1, 0x8c, 0x64, 0xac, 0x23, 0x05, 0x5f, 0x9b, 0xc0, 0xe9, 0x22, 0xce, 0x08, 0x4a, 0x64, - 0x1c, 0x28, 0xca, 0x29, 0xd6, 0x85, 0x00, 0x71, 0x2e, 0x71, 0xa6, 0x3c, 0x6b, 0x2e, 0x9a, 0x37, - 0xc7, 0x1b, 0x6b, 0x87, 0xc7, 0x35, 0xe3, 0xeb, 0x71, 0xed, 0x46, 0xc8, 0x92, 0x9d, 0xb4, 0xe5, - 0x62, 0xd9, 0xe9, 0x6b, 0xf7, 0x3f, 0xcb, 0x8a, 0xb4, 0xbd, 0xa4, 0x17, 0x51, 0xe5, 0x36, 0x29, - 0xfe, 0xfc, 0x71, 0x19, 0xf4, 0x5b, 0x6b, 0x52, 0xec, 0xcf, 0x9f, 0x69, 0x6c, 0x0e, 0x24, 0xee, - 0x9d, 0x29, 0xc0, 0x0e, 0xb8, 0xb4, 0x23, 0x39, 0x61, 0x22, 0x54, 0x45, 0xe1, 0xca, 0x05, 0x08, - 0xc3, 0x01, 0x71, 0x41, 0x8e, 0x81, 0x69, 0x2e, 0x71, 0x3b, 0x8d, 0x8a, 0x62, 0x23, 0x17, 0x20, - 0x66, 0xe7, 0xb4, 0xbf, 0xa4, 0x56, 0xad, 0x83, 0xf7, 0x35, 0x63, 0xe9, 0xad, 0x09, 0xc6, 0x37, - 0x50, 0x8c, 0x3a, 0x2a, 0xe8, 0xd6, 0xe1, 0x3e, 0x98, 0x25, 0x05, 0x37, 0xb4, 0x8f, 0x03, 0x3b, - 0xb2, 0x7f, 0x3d, 0xb1, 0xb2, 0xe6, 0x9e, 0x63, 0x0e, 0xdc, 0xbf, 0x58, 0xda, 0xb0, 0xf4, 0x19, - 0xfc, 0x19, 0x52, 0x5e, 0x5e, 0x1d, 0xd3, 0x2d, 0xbd, 0xd3, 0x6d, 0x7d, 0x32, 0xc1, 0x68, 0xde, - 0xd6, 0x3f, 0xee, 0x09, 0x5e, 0x07, 0xff, 0x63, 0x8e, 0x58, 0x47, 0x05, 0x54, 0xa0, 0x16, 0xa7, - 0x24, 0xf3, 0x7e, 0xcc, 0x9f, 0xca, 0xb3, 0xf7, 0xf3, 0x64, 0xa1, 0xf5, 0x7d, 0x30, 0xfd, 0x80, - 0xf6, 0x28, 0xd9, 0xd0, 0x03, 0x8e, 0x25, 0x6f, 0xa2, 0x04, 0x41, 0x1b, 0x8c, 0xb4, 0x69, 0x2f, - 0x9f, 0x57, 0x5f, 0x87, 0xf0, 0x29, 0x98, 0x8a, 0xfa, 0x88, 0x80, 0xa0, 0x04, 0x65, 0xb4, 0x13, - 0x2b, 0xf5, 0x73, 0x9d, 0xa5, 0xc8, 0xed, 0x4f, 0x46, 0x85, 0xd5, 0xd2, 0x16, 0x98, 0xfc, 0x4d, - 0x19, 0x02, 0x4b, 0xcf, 0x44, 0x5f, 0x3a, 0x8b, 0xe1, 0x6d, 0x60, 0x9d, 0x49, 0x4e, 0x36, 0xe6, - 0xbf, 0x1f, 0xd7, 0x66, 0xa9, 0xc0, 0x52, 0x0f, 0xa3, 0xf7, 0x42, 0x49, 0xe1, 0xfa, 0x68, 0xef, - 0x11, 0x55, 0x0a, 0x85, 0xd4, 0xcf, 0x90, 0xb7, 0x5e, 0x55, 0x80, 0x5d, 0xa4, 0xdd, 0xd2, 0x34, - 0x0b, 0x60, 0x6e, 0x38, 0xf7, 0x44, 0x10, 0xba, 0xcd, 0x04, 0x25, 0xb6, 0x01, 0x1d, 0x50, 0x1d, - 0x2e, 0xaf, 0x4b, 0x21, 0xf2, 0x2b, 0x66, 0x9b, 0xf0, 0x2a, 0x58, 0x18, 0xae, 0x3f, 0xd6, 0xf3, - 0xca, 0x54, 0xee, 0xbc, 0x5d, 0x81, 0x35, 0x70, 0x65, 0x18, 0xf2, 0x90, 0xed, 0xa6, 0x8c, 0x6c, - 0xc9, 0x36, 0x15, 0xf6, 0x48, 0x19, 0x60, 0xc0, 0x21, 0x25, 0xb7, 0x2d, 0xb8, 0x08, 0xe6, 0xff, - 0x68, 0x22, 0xa6, 0x0a, 0x53, 0x91, 0x64, 0x88, 0xff, 0xca, 0x10, 0x9b, 0x6c, 0x1b, 0xef, 0x20, - 0x26, 0x32, 0xc4, 0x68, 0xd5, 0x3a, 0xf8, 0xe0, 0x18, 0x8d, 0xe7, 0x87, 0x27, 0x8e, 0x79, 0x74, - 0xe2, 0x98, 0xdf, 0x4e, 0x1c, 0xf3, 0xcd, 0xa9, 0x63, 0x1c, 0x9d, 0x3a, 0xc6, 0x97, 0x53, 0xc7, - 0x78, 0xb6, 0x5e, 0xb8, 0x91, 0x4c, 0x84, 0x54, 0xa4, 0x2c, 0xe9, 0x2d, 0xb7, 0x52, 0xc6, 0x89, - 0x57, 0x7c, 0x75, 0x5f, 0x96, 0xbf, 0xbb, 0xd9, 0x95, 0x6d, 0x8d, 0x66, 0x2e, 0xde, 0xf9, 0x19, - 0x00, 0x00, 0xff, 0xff, 0x16, 0x6f, 0x81, 0xb8, 0xa8, 0x05, 0x00, 0x00, + // 621 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xc1, 0x6f, 0xd3, 0x3e, + 0x14, 0x4e, 0xba, 0xfc, 0xa6, 0xfd, 0xbc, 0x0d, 0x65, 0x06, 0x69, 0x5b, 0xd9, 0xd2, 0x31, 0x04, + 0x42, 0x48, 0x4b, 0xd8, 0xb8, 0x4d, 0x13, 0x12, 0x5d, 0x39, 0x01, 0x62, 0xca, 0x0a, 0x07, 0x24, + 0x54, 0xb9, 0xb6, 0x97, 0x9a, 0xba, 0x76, 0x16, 0x27, 0x1d, 0x3d, 0x4c, 0x42, 0x9c, 0x76, 0xe4, + 0xc8, 0x11, 0x89, 0x7f, 0x81, 0x03, 0x7f, 0xc2, 0x8e, 0x13, 0x27, 0xc4, 0xa1, 0x42, 0xed, 0x7f, + 0xc1, 0x01, 0x21, 0x27, 0x6d, 0x09, 0xa5, 0x93, 0x76, 0xd8, 0x29, 0xcf, 0xcf, 0x9f, 0xbf, 0xef, + 0xf9, 0x7d, 0x2f, 0x06, 0x0f, 0x0e, 0x13, 0x86, 0x9b, 0x8a, 0xf1, 0x36, 0x8d, 0xbc, 0x10, 0x45, + 0x31, 0xc3, 0x2c, 0x44, 0x31, 0x93, 0x22, 0xa2, 0x47, 0x28, 0x22, 0xca, 0x6b, 0x6f, 0x4e, 0xcc, + 0xbb, 0x61, 0x24, 0x63, 0x09, 0x6f, 0xe6, 0xce, 0xbb, 0x13, 0x71, 0xed, 0xcd, 0xe2, 0x32, 0x96, + 0xaa, 0x25, 0x55, 0x2d, 0x3d, 0xe2, 0x65, 0x8b, 0xec, 0x7c, 0xf1, 0x5a, 0x20, 0x03, 0x99, 0xe5, + 0x75, 0x94, 0x65, 0xd7, 0x7f, 0x15, 0xc0, 0x62, 0x85, 0xa9, 0x38, 0x62, 0xf5, 0x44, 0x73, 0xed, + 0x45, 0x32, 0x94, 0x91, 0x8e, 0x14, 0x7c, 0x67, 0x02, 0xa7, 0x8d, 0x38, 0x23, 0x28, 0x96, 0x51, + 0x4d, 0x51, 0x4e, 0xb1, 0xde, 0xa8, 0x21, 0xce, 0x25, 0x4e, 0x95, 0x97, 0xcc, 0x35, 0xf3, 0xce, + 0xff, 0xe5, 0x9d, 0xd3, 0x6e, 0xc9, 0xf8, 0xde, 0x2d, 0xdd, 0x0e, 0x58, 0xdc, 0x48, 0xea, 0x2e, + 0x96, 0xad, 0x81, 0xf6, 0xe0, 0xb3, 0xa1, 0x48, 0xd3, 0x8b, 0x3b, 0x21, 0x55, 0x6e, 0x85, 0xe2, + 0xaf, 0x9f, 0x37, 0xc0, 0xa0, 0xb4, 0x0a, 0xc5, 0xfe, 0xca, 0x48, 0x63, 0x7f, 0x28, 0xf1, 0x70, + 0xa4, 0x00, 0x5b, 0xe0, 0x6a, 0x43, 0x72, 0xc2, 0x44, 0xa0, 0xf2, 0xc2, 0x85, 0x4b, 0x10, 0x86, + 0x43, 0xe2, 0x9c, 0x1c, 0x03, 0x0b, 0x5c, 0xe2, 0x66, 0x12, 0xe6, 0xc5, 0xa6, 0x2e, 0x41, 0xcc, + 0xce, 0x68, 0xff, 0x48, 0x6d, 0x5b, 0x27, 0x1f, 0x4b, 0xc6, 0xfa, 0x17, 0x13, 0x4c, 0xef, 0xa1, + 0x08, 0xb5, 0x14, 0x3c, 0x06, 0x4b, 0x24, 0x67, 0x85, 0x36, 0x71, 0xe8, 0x45, 0xda, 0xe8, 0xd9, + 0xad, 0x1d, 0xf7, 0x02, 0x43, 0xe0, 0x9e, 0xe3, 0x67, 0xd9, 0xd2, 0x17, 0xf0, 0x17, 0xc9, 0x39, + 0x76, 0xdf, 0x02, 0x57, 0x30, 0x47, 0xac, 0xa5, 0x6a, 0x54, 0xa0, 0x3a, 0xa7, 0x24, 0x6d, 0xf2, + 0x8c, 0x3f, 0x9f, 0x65, 0x1f, 0x65, 0xc9, 0xed, 0x19, 0x5d, 0xf6, 0x07, 0x5d, 0xfa, 0x31, 0x58, + 0x78, 0x4c, 0x3b, 0x94, 0xec, 0xe9, 0x49, 0xc2, 0x92, 0x57, 0x50, 0x8c, 0xa0, 0x0d, 0xa6, 0x9a, + 0xb4, 0x93, 0x0d, 0x86, 0xaf, 0x43, 0xf8, 0x02, 0xcc, 0x87, 0x03, 0x44, 0x8d, 0xa0, 0x18, 0xa5, + 0xb4, 0xb3, 0x5b, 0x9b, 0x17, 0xba, 0x4b, 0x9e, 0xdb, 0x9f, 0x0b, 0x73, 0xab, 0xf5, 0x2a, 0x98, + 0xfb, 0x4b, 0x19, 0x02, 0x4b, 0x37, 0x7f, 0x20, 0x9d, 0xc6, 0xf0, 0x1e, 0xb0, 0x46, 0x92, 0x73, + 0xe5, 0x95, 0x9f, 0xdd, 0xd2, 0x12, 0x15, 0x58, 0x6a, 0xd7, 0xbd, 0xd7, 0x4a, 0x0a, 0xd7, 0x47, + 0x47, 0x4f, 0xa9, 0x52, 0x28, 0xa0, 0x7e, 0x8a, 0xbc, 0xfb, 0xb6, 0x00, 0xec, 0x3c, 0x6d, 0x55, + 0xd3, 0xac, 0x82, 0xe5, 0xf1, 0xdc, 0x73, 0x41, 0xe8, 0x01, 0x13, 0x94, 0xd8, 0x06, 0x74, 0x40, + 0x71, 0x7c, 0x7b, 0x57, 0x0a, 0x91, 0xcd, 0xb2, 0x6d, 0xc2, 0x1b, 0x60, 0x75, 0x7c, 0xff, 0x99, + 0x1e, 0x0c, 0xa6, 0x32, 0xe7, 0xed, 0x02, 0x2c, 0x81, 0xeb, 0xe3, 0x90, 0x27, 0xec, 0x30, 0x61, + 0xa4, 0x2a, 0x9b, 0x54, 0xd8, 0x53, 0x93, 0x00, 0x43, 0x0e, 0x29, 0xb9, 0x6d, 0xc1, 0x35, 0xb0, + 0xf2, 0x4f, 0x11, 0x11, 0x55, 0x98, 0x8a, 0x38, 0x45, 0xfc, 0x37, 0x09, 0xb1, 0xcf, 0x0e, 0x70, + 0x03, 0x31, 0x91, 0x22, 0xa6, 0x8b, 0xd6, 0xc9, 0x27, 0xc7, 0x28, 0xbf, 0x3a, 0xed, 0x39, 0xe6, + 0x59, 0xcf, 0x31, 0x7f, 0xf4, 0x1c, 0xf3, 0x7d, 0xdf, 0x31, 0xce, 0xfa, 0x8e, 0xf1, 0xad, 0xef, + 0x18, 0x2f, 0x77, 0x73, 0xa3, 0xcf, 0x44, 0x40, 0x45, 0xc2, 0xe2, 0xce, 0x46, 0x3d, 0x61, 0x9c, + 0x78, 0xf9, 0xe7, 0xed, 0xcd, 0xe4, 0x07, 0x2e, 0xfd, 0x37, 0xea, 0xd3, 0xa9, 0x8b, 0xf7, 0x7f, + 0x07, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x87, 0x46, 0x1b, 0x11, 0x05, 0x00, 0x00, } func (m *DistributionProportions) Marshal() (dAtA []byte, err error) { @@ -403,39 +362,6 @@ func (m *DistributionProportions) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func (m *ParamsV1) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ParamsV1) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ParamsV1) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.DistributionProportions.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintParticipationrewards(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - func (m *Params) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -584,17 +510,6 @@ func (m *DistributionProportions) Size() (n int) { return n } -func (m *ParamsV1) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.DistributionProportions.Size() - n += 1 + l + sovParticipationrewards(uint64(l)) - return n -} - func (m *Params) Size() (n int) { if m == nil { return 0 @@ -801,89 +716,6 @@ func (m *DistributionProportions) Unmarshal(dAtA []byte) error { } return nil } -func (m *ParamsV1) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParticipationrewards - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Params_v1: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Params_v1: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DistributionProportions", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParticipationrewards - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthParticipationrewards - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthParticipationrewards - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.DistributionProportions.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipParticipationrewards(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthParticipationrewards - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *Params) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 From 8f9c1a5b5691131fe0b99adb1ec4d37b98567c99 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Thu, 8 Jun 2023 15:50:30 +0100 Subject: [PATCH 18/25] lint --- .../gamm/pool-models/balancer/pool.go | 1 - utils/addressutils/address_test.go | 13 ++-- utils/randomutils/random_test.go | 4 +- .../keeper/address_map_test.go | 72 +++++++++---------- x/interchainstaking/keeper/grpc_query_test.go | 24 +++---- x/interchainstaking/keeper/receipt.go | 4 +- 6 files changed, 57 insertions(+), 61 deletions(-) diff --git a/osmosis-types/gamm/pool-models/balancer/pool.go b/osmosis-types/gamm/pool-models/balancer/pool.go index 9f17f8718..55c3dd058 100644 --- a/osmosis-types/gamm/pool-models/balancer/pool.go +++ b/osmosis-types/gamm/pool-models/balancer/pool.go @@ -80,7 +80,6 @@ func (p Pool) GetAddress() sdk.AccAddress { panic(fmt.Sprintf("could not bech32 decode address of pool with id: %d", p.GetId())) } return addr - } func (p Pool) GetId() uint64 { diff --git a/utils/addressutils/address_test.go b/utils/addressutils/address_test.go index 36a21a6d1..92bf4663b 100644 --- a/utils/addressutils/address_test.go +++ b/utils/addressutils/address_test.go @@ -112,24 +112,24 @@ func TestAddressFromBech32(t *testing.T) { require.Panics(t, func() { addressutils.MustAccAddressFromBech32(c.address, c.prefix) }) require.Panics(t, func() { addressutils.MustValAddressFromBech32(c.address, c.prefix) }) } else { - var addr sdk.AccAddress = addressutils.MustAccAddressFromBech32(c.address, c.prefix) + addr := addressutils.MustAccAddressFromBech32(c.address, c.prefix) require.Equal(t, c.expectedBytes, addr.Bytes()) - var valaddr sdk.ValAddress = addressutils.MustValAddressFromBech32(c.address, c.prefix) + valaddr := addressutils.MustValAddressFromBech32(c.address, c.prefix) require.Equal(t, c.expectedBytes, valaddr.Bytes()) } } } func TestGenerateAccAddressForTest(t *testing.T) { - var address sdk.AccAddress = addressutils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() require.Equal(t, 32, len(address.Bytes())) err := sdk.VerifyAddressFormat(address.Bytes()) require.NoError(t, err) } func TestGenerateValAddressForTest(t *testing.T) { - var address sdk.ValAddress = addressutils.GenerateValAddressForTest() + address := addressutils.GenerateValAddressForTest() require.Equal(t, 32, len(address.Bytes())) err := sdk.VerifyAddressFormat(address.Bytes()) require.NoError(t, err) @@ -142,7 +142,6 @@ func TestGenerateAddressForTestWithPrefix(t *testing.T) { } func TestEncodeAddressToBech32(t *testing.T) { - cases := []struct { name string addrBytes []byte @@ -165,14 +164,14 @@ func TestEncodeAddressToBech32(t *testing.T) { "", }, { - "suprisingly valid, nil", + "surprisingly valid, nil", nil, "cosmos", "cosmos1550dq7", "", }, { - "even more suprisingly valid - no hrp :/", + "even more surprisingly valid - no hrp :/", []byte{0xb3, 0x2b, 0x91, 0x3c, 0x68, 0x1b, 0x75, 0xe2, 0xef, 0x4d, 0xe9, 0x75, 0xd0, 0xcc, 0x6, 0xb6, 0x3b, 0xbb, 0xa8, 0xf8}, "", "1kv4ez0rgrd679m6da96apnqxkcamh28cjkahle", diff --git a/utils/randomutils/random_test.go b/utils/randomutils/random_test.go index 0f6e78d13..d692bd294 100644 --- a/utils/randomutils/random_test.go +++ b/utils/randomutils/random_test.go @@ -14,12 +14,12 @@ import ( func TestGenerateRandomHash(t *testing.T) { random := rand.New(rand.NewSource(time.Now().UnixNano())) b := random.Intn(128) - var byteslice []byte = randomutils.GenerateRandomBytes(b) + byteslice := randomutils.GenerateRandomBytes(b) require.Equal(t, b, len(byteslice)) } func TestGenerateRandomHashAsHex(t *testing.T) { - var hexHash string = randomutils.GenerateRandomHashAsHex(32) + hexHash := randomutils.GenerateRandomHashAsHex(32) require.Equal(t, 64, len(hexHash)) byteslice, err := hex.DecodeString(hexHash) require.NoError(t, err) diff --git a/x/interchainstaking/keeper/address_map_test.go b/x/interchainstaking/keeper/address_map_test.go index b9c0c8dfb..fa0288b06 100644 --- a/x/interchainstaking/keeper/address_map_test.go +++ b/x/interchainstaking/keeper/address_map_test.go @@ -8,85 +8,85 @@ const ( testChainID = "test-1" ) -func (s *KeeperTestSuite) TestKeeper_RemoteAddressStore() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestKeeper_RemoteAddressStore() { + suite.SetupTest() + suite.setupTestZones() - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() localAddress := randomutils.GenerateRandomBytes(28) remoteAddress := randomutils.GenerateRandomBytes(40) - s.Run("not found", func() { + suite.Run("not found", func() { _, found := icsKeeper.GetRemoteAddressMap(ctx, localAddress, testChainID) - s.Require().False(found) + suite.Require().False(found) }) - s.Run("set", func() { + suite.Run("set", func() { icsKeeper.SetRemoteAddressMap(ctx, localAddress, remoteAddress, testChainID) }) - s.Run("found", func() { + suite.Run("found", func() { addr, found := icsKeeper.GetRemoteAddressMap(ctx, localAddress, testChainID) - s.Require().True(found) - s.Require().Equal(remoteAddress, addr) + suite.Require().True(found) + suite.Require().Equal(remoteAddress, addr) }) } -func (s *KeeperTestSuite) TestKeeper_LocalAddressStore() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestKeeper_LocalAddressStore() { + suite.SetupTest() + suite.setupTestZones() - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() localAddress := randomutils.GenerateRandomBytes(28) remoteAddress := randomutils.GenerateRandomBytes(40) - s.Run("not found", func() { + suite.Run("not found", func() { _, found := icsKeeper.GetLocalAddressMap(ctx, remoteAddress, testChainID) - s.Require().False(found) + suite.Require().False(found) }) - s.Run("set", func() { + suite.Run("set", func() { icsKeeper.SetLocalAddressMap(ctx, localAddress, remoteAddress, testChainID) }) - s.Run("found", func() { + suite.Run("found", func() { addr, found := icsKeeper.GetLocalAddressMap(ctx, remoteAddress, testChainID) - s.Require().True(found) - s.Require().Equal(localAddress, addr) + suite.Require().True(found) + suite.Require().Equal(localAddress, addr) }) } -func (s *KeeperTestSuite) TestKeeper_AddressMapPair() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestKeeper_AddressMapPair() { + suite.SetupTest() + suite.setupTestZones() - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() localAddress := randomutils.GenerateRandomBytes(28) remoteAddress := randomutils.GenerateRandomBytes(40) - s.Run("not found", func() { + suite.Run("not found", func() { _, found := icsKeeper.GetLocalAddressMap(ctx, remoteAddress, testChainID) - s.Require().False(found) + suite.Require().False(found) _, found = icsKeeper.GetRemoteAddressMap(ctx, remoteAddress, testChainID) - s.Require().False(found) + suite.Require().False(found) }) - s.Run("set", func() { + suite.Run("set", func() { icsKeeper.SetAddressMapPair(ctx, localAddress, remoteAddress, testChainID) }) - s.Run("found", func() { + suite.Run("found", func() { addr, found := icsKeeper.GetLocalAddressMap(ctx, remoteAddress, testChainID) - s.Require().True(found) - s.Require().Equal(localAddress, addr) + suite.Require().True(found) + suite.Require().Equal(localAddress, addr) addr, found = icsKeeper.GetRemoteAddressMap(ctx, localAddress, testChainID) - s.Require().True(found) - s.Require().Equal(remoteAddress, addr) + suite.Require().True(found) + suite.Require().Equal(remoteAddress, addr) }) } diff --git a/x/interchainstaking/keeper/grpc_query_test.go b/x/interchainstaking/keeper/grpc_query_test.go index 3dc15ff6a..6404d0659 100644 --- a/x/interchainstaking/keeper/grpc_query_test.go +++ b/x/interchainstaking/keeper/grpc_query_test.go @@ -835,10 +835,10 @@ func (suite *KeeperTestSuite) TestKeeper_RedelegationRecords() { } } -func (s *KeeperTestSuite) TestKeeper_MappedAccounts() { - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper +func (suite *KeeperTestSuite) TestKeeper_MappedAccounts() { + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper usrAddress1, _ := addressutils.AccAddressFromBech32("cosmos1vwh8mkgefn73vpsv7td68l3tynayck07engahn", "cosmos") - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() tests := []struct { name string @@ -878,7 +878,7 @@ func (s *KeeperTestSuite) TestKeeper_MappedAccounts() { "MappedAccounts_ValidRecord_Request", func() { // setup zones - s.setupTestZones() + suite.setupTestZones() zone := types.Zone{ ConnectionId: "connection-77881", ChainId: "evmos_9001-1", @@ -938,25 +938,25 @@ func (s *KeeperTestSuite) TestKeeper_MappedAccounts() { // run tests: for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() resp, err := icsKeeper.MappedAccounts( ctx, tt.req, ) if tt.wantErr { - s.T().Logf("Error:\n%v\n", err) - s.Require().Error(err) + suite.T().Logf("Error:\n%v\n", err) + suite.Require().Error(err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.expectLength, len(resp.RemoteAddressMap)) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.expectLength, len(resp.RemoteAddressMap)) vstr, err := json.MarshalIndent(resp, "", "\t") - s.Require().NoError(err) + suite.Require().NoError(err) - s.T().Logf("Response:\n%s\n", vstr) + suite.T().Logf("Response:\n%s\n", vstr) }) } } diff --git a/x/interchainstaking/keeper/receipt.go b/x/interchainstaking/keeper/receipt.go index 3d0d9026d..6b9abe7eb 100644 --- a/x/interchainstaking/keeper/receipt.go +++ b/x/interchainstaking/keeper/receipt.go @@ -65,14 +65,12 @@ func (k Keeper) HandleReceiptTransaction(ctx sdk.Context, txn *tx.Tx, txHash str k.NilReceipt(ctx, &zone, hash) // nil receipt will stop this hash being submitted again return nil } - // sdk.AccAddressFromBech32 doesn't work here as it expects the local HRP - addressBytes, err := addressutils.AccAddressFromBech32(senderAddress, zone.GetAccountPrefix()) + senderAccAddress, err := addressutils.AccAddressFromBech32(senderAddress, zone.GetAccountPrefix()) if err != nil { k.Logger(ctx).Error("unable to decode sender address. Ignoring.", "senderAddress", senderAddress, "error", err) k.NilReceipt(ctx, &zone, hash) // nil receipt will stop this hash being submitted again return nil } - var senderAccAddress sdk.AccAddress = addressBytes if err := zone.ValidateCoinsForZone(assets, k.GetValidatorAddresses(ctx, zone.ChainId)); err != nil { // we expect this to trigger if the validatorset has changed recently (i.e. we haven't seen the validator before. From 27174c03a2b4fea5036d63f507cb890a8f5172a4 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Fri, 9 Jun 2023 11:54:24 +0100 Subject: [PATCH 19/25] fix nits --- .../gamm/pool-models/balancer/marshal.go | 57 ++----------------- .../gamm/pool-models/stableswap/pool.go | 4 +- x/interchainstaking/keeper/receipt.go | 3 +- 3 files changed, 8 insertions(+), 56 deletions(-) diff --git a/osmosis-types/gamm/pool-models/balancer/marshal.go b/osmosis-types/gamm/pool-models/balancer/marshal.go index 0d3afa414..c00dff48b 100644 --- a/osmosis-types/gamm/pool-models/balancer/marshal.go +++ b/osmosis-types/gamm/pool-models/balancer/marshal.go @@ -4,15 +4,11 @@ import ( "encoding/json" ) -// type balancerPoolPretty struct { -// Address sdk.AccAddress `json:"address" yaml:"address"` -// Id uint64 `json:"id" yaml:"id"` -// PoolParams PoolParams `json:"pool_params" yaml:"pool_params"` -// FuturePoolGovernor string `json:"future_pool_governor" yaml:"future_pool_governor"` -// TotalWeight sdk.Dec `json:"total_weight" yaml:"total_weight"` -// TotalShares sdk.Coin `json:"total_shares" yaml:"total_shares"` -// PoolAssets []PoolAsset `json:"pool_assets" yaml:"pool_assets"` -// } +// Upstream marshal.go contains balancerPoolPretty and custom +// JSONMarshal and JSONUnmarshal functions. Given that we deal +// directly with the value in the KV store, not the output from +// a query, we do not need to use these methods and they are +// removed below. func (p Pool) String() string { out, err := json.Marshal(p) @@ -21,46 +17,3 @@ func (p Pool) String() string { } return string(out) } - -// MarshalJSON returns the JSON representation of a Pool. -// func (p Pool) MarshalJSON() ([]byte, error) { -// if len(strings.TrimSpace(p.Address)) == 0 { -// return nil, errors.New("empty address string is not allowed") -// } - -// accAddr, err := sdk.GetFromBech32(p.Address, "osmo") -// // accAddr, err := sdk.AccAddressFromBech32(p.Address) -// if err != nil { -// return nil, err -// } - -// decTotalWeight := sdk.NewDecFromInt(p.TotalWeight) - -// return json.Marshal(balancerPoolPretty{ -// Address: accAddr, -// Id: p.Id, -// PoolParams: p.PoolParams, -// FuturePoolGovernor: p.FuturePoolGovernor, -// TotalWeight: decTotalWeight, -// TotalShares: p.TotalShares, -// PoolAssets: p.PoolAssets, -// }) -// } - -// UnmarshalJSON unmarshals raw JSON bytes into a Pool. -// func (p *Pool) UnmarshalJSON(bz []byte) error { -// var alias balancerPoolPretty -// if err := json.Unmarshal(bz, &alias); err != nil { -// return err -// } - -// p.Address = alias.Address.String() -// p.Id = alias.Id -// p.PoolParams = alias.PoolParams -// p.FuturePoolGovernor = alias.FuturePoolGovernor -// p.TotalWeight = alias.TotalWeight.RoundInt() -// p.TotalShares = alias.TotalShares -// p.PoolAssets = alias.PoolAssets - -// return nil -// } diff --git a/osmosis-types/gamm/pool-models/stableswap/pool.go b/osmosis-types/gamm/pool-models/stableswap/pool.go index faa5de210..2e6dacb13 100644 --- a/osmosis-types/gamm/pool-models/stableswap/pool.go +++ b/osmosis-types/gamm/pool-models/stableswap/pool.go @@ -8,10 +8,10 @@ import ( sdkioerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/internal/cfmm_common" + "github.com/ingenuity-build/quicksilver/utils/addressutils" ) var _ gamm.PoolI = &Pool{} @@ -42,7 +42,7 @@ func NewStableswapPool(poolId uint64, stableswapPoolParams PoolParams, initialLi } func (p Pool) GetAddress() sdk.AccAddress { - _, addr, err := bech32.DecodeAndConvert(p.Address) + addr, err := addressutils.AccAddressFromBech32(p.Address, "") if err != nil { panic(fmt.Sprintf("could not bech32 decode address of pool with id: %d", p.GetId())) } diff --git a/x/interchainstaking/keeper/receipt.go b/x/interchainstaking/keeper/receipt.go index 6b9abe7eb..531df4032 100644 --- a/x/interchainstaking/keeper/receipt.go +++ b/x/interchainstaking/keeper/receipt.go @@ -25,9 +25,8 @@ const ( ICATimeout = time.Hour * 6 ) -func (k Keeper) HandleReceiptTransaction(ctx sdk.Context, txn *tx.Tx, txHash string, zone types.Zone) error { +func (k Keeper) HandleReceiptTransaction(ctx sdk.Context, txn *tx.Tx, hash string, zone types.Zone) error { k.Logger(ctx).Info("Deposit receipt.", "ischeck", ctx.IsCheckTx(), "isrecheck", ctx.IsReCheckTx()) - hash := txHash memo := txn.Body.Memo senderAddress := Unset From 87ed29ee124668ee657efa3227419ef9ce386145 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Fri, 9 Jun 2023 12:15:57 +0100 Subject: [PATCH 20/25] bump go to 1.20.5 --- .github/workflows/buildtest.yaml | 10 +++++----- .github/workflows/docker.yaml | 7 +++---- .github/workflows/golangci.yml | 2 +- .github/workflows/interchaintest.yaml | 22 ++++++++++------------ .github/workflows/simulation.yml | 4 ++-- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/.github/workflows/buildtest.yaml b/.github/workflows/buildtest.yaml index 31eb53ece..f969c3b52 100644 --- a/.github/workflows/buildtest.yaml +++ b/.github/workflows/buildtest.yaml @@ -29,7 +29,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" env: GOOS: ${{ matrix.targetos }} GOARCH: ${{ matrix.arch }} @@ -63,7 +63,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" env: GOOS: ${{ matrix.targetos }} GOARCH: ${{ matrix.arch }} @@ -93,10 +93,10 @@ jobs: filename=$(echo $filename | sed 's/^./github.com\/ingenuity-build\/quicksilver/g') echo "Excluding ${filename} from coverage report..." sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt - done + done - name: "Go vulnerability checks" - continue-on-error: false #temp-till we upgrade to v1.20 + continue-on-error: false #temp-till we upgrade to v1.20 run: make vulncheck - name: Upload coverage reports to Codecov with GitHub Action @@ -124,6 +124,6 @@ jobs: ${{ runner.os }}-go- - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" - name: Run simulation tests run: make test-sim-ci diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index c3d95b01a..d4b2b2bb0 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -3,13 +3,12 @@ name: Docker on: push: branches: - - 'develop' + - "develop" jobs: docker: runs-on: ubuntu-latest steps: - - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -25,7 +24,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" - name: Setup Golang caches uses: actions/cache@v3 @@ -40,4 +39,4 @@ jobs: - name: build and push container run: | DOCKER_BUILDKIT=1 /usr/bin/docker build . -f Dockerfile -t quicksilverzone/quicksilver:latest - /usr/bin/docker push quicksilverzone/quicksilver:latest + /usr/bin/docker push quicksilverzone/quicksilver:latest diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml index d2d44f57a..66c55b3c0 100644 --- a/.github/workflows/golangci.yml +++ b/.github/workflows/golangci.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 diff --git a/.github/workflows/interchaintest.yaml b/.github/workflows/interchaintest.yaml index 32fc10388..8bb4b31a8 100644 --- a/.github/workflows/interchaintest.yaml +++ b/.github/workflows/interchaintest.yaml @@ -3,13 +3,13 @@ name: create docker image + E2E Tests on: push: tags: - - '**' + - "**" branches: - - 'main' - - 'develop' + - "main" + - "develop" paths: - - '**.go' - - 'go.sum' + - "**.go" + - "go.sum" env: REGISTRY: quicksilverzone @@ -23,7 +23,6 @@ jobs: build-and-push-image: runs-on: ubuntu-latest steps: - - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -39,10 +38,9 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" - - - name: Build and push + - name: Build and push id: build_push_image uses: docker/build-push-action@v3 with: @@ -60,7 +58,7 @@ jobs: - name: Set up Go 1.20 uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" id: go - name: checkout chain @@ -77,7 +75,7 @@ jobs: - name: Set up Go 1.20 uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" id: go - name: checkout chain @@ -94,7 +92,7 @@ jobs: - name: Set up Go 1.20 uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" id: go - name: checkout chain diff --git a/.github/workflows/simulation.yml b/.github/workflows/simulation.yml index b00becf5b..de9f6a0b7 100644 --- a/.github/workflows/simulation.yml +++ b/.github/workflows/simulation.yml @@ -2,7 +2,7 @@ name: simulate quicksilver on: schedule: - - cron: '0 0 * * 0' # run once a week + - cron: "0 0 * * 0" # run once a week jobs: simulate: @@ -19,7 +19,7 @@ jobs: ${{ runner.os }}-go- - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" - name: Run simulation tests run: make test-sim-non-determinism From 729e5bfdb970c46a22234e570ce8ac822dd15297 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Mon, 12 Jun 2023 11:12:52 +0100 Subject: [PATCH 21/25] Update x/interchainstaking/keeper/receipt.go --- x/interchainstaking/keeper/receipt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/interchainstaking/keeper/receipt.go b/x/interchainstaking/keeper/receipt.go index 531df4032..5366ebcfc 100644 --- a/x/interchainstaking/keeper/receipt.go +++ b/x/interchainstaking/keeper/receipt.go @@ -25,7 +25,7 @@ const ( ICATimeout = time.Hour * 6 ) -func (k Keeper) HandleReceiptTransaction(ctx sdk.Context, txn *tx.Tx, hash string, zone types.Zone) error { +func (k *Keeper) HandleReceiptTransaction(ctx sdk.Context, txn *tx.Tx, hash string, zone types.Zone) error { k.Logger(ctx).Info("Deposit receipt.", "ischeck", ctx.IsCheckTx(), "isrecheck", ctx.IsReCheckTx()) memo := txn.Body.Memo From f69e7b918381d024a2f5a8d3ca65dfde2d2f9183 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Mon, 12 Jun 2023 11:22:10 +0100 Subject: [PATCH 22/25] Apply suggestions from code review --- x/interchainstaking/keeper/delegation.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x/interchainstaking/keeper/delegation.go b/x/interchainstaking/keeper/delegation.go index d747330c2..7515927ae 100644 --- a/x/interchainstaking/keeper/delegation.go +++ b/x/interchainstaking/keeper/delegation.go @@ -282,7 +282,6 @@ func (k *Keeper) MakePerformanceDelegation(ctx sdk.Context, zone *types.Zone, va func (k *Keeper) FlushOutstandingDelegations(ctx sdk.Context, zone *types.Zone, delAddrBalance sdk.Coin) error { var pendingAmount sdk.Coins exclusionTime := ctx.BlockTime().AddDate(0, 0, -1) - var coinsToFlush sdk.Coins k.IterateZoneReceipts(ctx, zone, func(_ int64, receiptInfo types.Receipt) (stop bool) { if (receiptInfo.FirstSeen.After(exclusionTime) || receiptInfo.FirstSeen.Equal(exclusionTime)) && receiptInfo.Completed == nil { pendingAmount = pendingAmount.Add(receiptInfo.Amount...) @@ -290,9 +289,8 @@ func (k *Keeper) FlushOutstandingDelegations(ctx sdk.Context, zone *types.Zone, return false }) - var hasNeg bool - coinsToFlush, hasNeg = sdk.NewCoins(delAddrBalance).SafeSub(pendingAmount...) + coinsToFlush, hasNeg := sdk.NewCoins(delAddrBalance).SafeSub(pendingAmount...) if hasNeg || coinsToFlush.IsZero() { k.Logger(ctx).Debug("delegate account balance negative, setting outdated reciepts") k.SetReceiptsCompleted(ctx, zone, exclusionTime, ctx.BlockTime()) From dcbb1fb98b8f4a21748be6dd7a93aefe15136ade Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Mon, 12 Jun 2023 11:31:34 +0100 Subject: [PATCH 23/25] lint --- x/interchainstaking/keeper/delegation.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/interchainstaking/keeper/delegation.go b/x/interchainstaking/keeper/delegation.go index 7515927ae..e12ebcf01 100644 --- a/x/interchainstaking/keeper/delegation.go +++ b/x/interchainstaking/keeper/delegation.go @@ -289,7 +289,6 @@ func (k *Keeper) FlushOutstandingDelegations(ctx sdk.Context, zone *types.Zone, return false }) - coinsToFlush, hasNeg := sdk.NewCoins(delAddrBalance).SafeSub(pendingAmount...) if hasNeg || coinsToFlush.IsZero() { k.Logger(ctx).Debug("delegate account balance negative, setting outdated reciepts") From ccf97e2875a2c5ee1688e6e998783753a940f97c Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Mon, 12 Jun 2023 11:33:10 +0100 Subject: [PATCH 24/25] bump hermes to v1.5.0 --- Dockerfile.hermes | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.hermes b/Dockerfile.hermes index ac5e9ad97..b618f01ae 100644 --- a/Dockerfile.hermes +++ b/Dockerfile.hermes @@ -4,7 +4,7 @@ RUN apt update && apt install git -y WORKDIR /app/src -RUN git clone https://github.com/informalsystems/ibc-rs --branch v1.4.0 +RUN git clone https://github.com/informalsystems/ibc-rs --branch v1.5.0 WORKDIR ibc-rs diff --git a/docker-compose.yml b/docker-compose.yml index 0c8db975e..b4983383e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -98,7 +98,7 @@ services: - osmosisd - start hermes: - image: quicksilverzone/hermes:v1.4.0 + image: quicksilverzone/hermes:v1.5.0 hostname: hermes volumes: - ./data/hermes:/hermes/.hermes From 974ea7fdc0a2f6cb471eda5983785c665ef4f3a2 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Mon, 12 Jun 2023 11:33:49 +0100 Subject: [PATCH 25/25] update icq and relayer in test scripts --- docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b4983383e..ae22d142a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -110,7 +110,7 @@ services: context: . dockerfile: Dockerfile.hermes icq: - image: quicksilverzone/interchain-queries:v0.8.7 + image: quicksilverzone/interchain-queries:v0.9.1 volumes: - ./data/icq:/icq/.icq command: @@ -118,7 +118,7 @@ services: - run restart: always icq2: - image: quicksilverzone/interchain-queries:v0.6.2 + image: quicksilverzone/interchain-queries:v0.9.1 volumes: - ./data/icq2:/icq/.icq command: @@ -126,7 +126,7 @@ services: - run restart: always relayer: - image: quicksilverzone/relayer:v2.1.1 + image: quicksilverzone/relayer:v2.3.0 build: context: . dockerfile: Dockerfile.relayer