diff --git a/Makefile b/Makefile index c07fb3568..3d82877cb 100644 --- a/Makefile +++ b/Makefile @@ -824,7 +824,7 @@ warn_message_local_stress_test: ## Print a warning message when kicking off a lo @echo "| |" @echo "| 1. Review the # of suppliers & gateways in 'load-testing/localnet_loadtest_manifest.yaml' |" @echo "| 2. Update 'localnet_config.yaml' to reflect what you found in (1) |" - @echo "| DEVELOPER_TIP: If you're operating off defaults, you'll likely need to update to 3 |" + @echo "| DEVELOPER_TIP: If you're operating off defaults, you'll likely need to update to 3 |" @echo "| |" @echo "| TODO_DOCUMENT(@okdas): Move this into proper documentation w/ clearer explanations |" @echo "| |" @@ -838,7 +838,7 @@ warn_flaky_tests: ## Print a warning message that some unit tests may be flaky @echo "| |" @echo "| 1. Our unit / integration tests are far from perfect & some are flaky |" @echo "| 2. If you ran 'make go_develop_and_test' and a failure occurred, try to run: |" - @echo "| 'make test_all' once or twice more |" + @echo "| 'make test_all' once or twice more |" @echo "| 3. If the same error persists, isolate it with 'go test -v ./path/to/failing/module |" @echo "| |" @echo "+-----------------------------------------------------------------------------------------------+" diff --git a/api/poktroll/supplier/tx.pulsar.go b/api/poktroll/supplier/tx.pulsar.go index 8c74573e5..c8e1c1b5e 100644 --- a/api/poktroll/supplier/tx.pulsar.go +++ b/api/poktroll/supplier/tx.pulsar.go @@ -2321,7 +2321,7 @@ func (x *fastReflection_MsgUnstakeSupplier) ProtoMethods() *protoiface.Methods { copy(dAtA[i:], x.Address) i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Address))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 } if len(x.Signer) > 0 { i -= len(x.Signer) @@ -2411,7 +2411,7 @@ func (x *fastReflection_MsgUnstakeSupplier) ProtoMethods() *protoiface.Methods { } x.Signer = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 2: if wireType != 2 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) } @@ -3021,7 +3021,7 @@ type MsgUnstakeSupplier struct { unknownFields protoimpl.UnknownFields Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` // The Bech32 address of the message signer (i.e. owner or operator) - Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"` // The Bech32 address of the operator (i.e. provider, non-custodial) + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` // The Bech32 address of the operator (i.e. provider, non-custodial) } func (x *MsgUnstakeSupplier) Reset() { @@ -3142,7 +3142,7 @@ var file_poktroll_supplier_tx_proto_rawDesc = []byte{ 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x32, 0x0a, 0x07, 0x61, 0x64, 0x64, - 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, + 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, 0x1c, 0x0a, 0x1a, 0x4d, 0x73, diff --git a/config.yml b/config.yml index 8f8e4429f..f6ffaa640 100644 --- a/config.yml +++ b/config.yml @@ -169,7 +169,8 @@ genesis: denom: upokt supplier: supplierList: - - address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj + - owner_address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj + address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj services: - service: id: anvil diff --git a/e2e/tests/init_test.go b/e2e/tests/init_test.go index 841d65b8e..c9dcaedc3 100644 --- a/e2e/tests/init_test.go +++ b/e2e/tests/init_test.go @@ -280,7 +280,8 @@ func (s *suite) TheUserStakesAWithUpoktForServiceFromTheAccount(actorType string require.NoError(s, err, "error creating config file in %q", path.Join(os.TempDir(), configPathPattern)) // Write the config content to the file - configContent := s.getConfigFileContent(amount, actorType, serviceId) + accAddress := accNameToAddrMap[accName] + configContent := s.getConfigFileContent(amount, accAddress, accAddress, actorType, serviceId) _, err = configFile.Write([]byte(configContent)) require.NoError(s, err, "error writing config file %q", configFile.Name()) @@ -307,7 +308,13 @@ func (s *suite) TheUserStakesAWithUpoktForServiceFromTheAccount(actorType string s.pocketd.result = res } -func (s *suite) getConfigFileContent(amount int64, actorType, serviceId string) string { +func (s *suite) getConfigFileContent( + amount int64, + ownerAddress, + operatorAddress, + actorType, + serviceId string, +) string { var configContent string switch actorType { case "application": @@ -318,13 +325,15 @@ func (s *suite) getConfigFileContent(amount int64, actorType, serviceId string) amount, serviceId) case "supplier": configContent = fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: %dupokt services: - service_id: %s endpoints: - publicly_exposed_url: http://relayminer:8545 rpc_type: json_rpc`, - amount, serviceId) + ownerAddress, operatorAddress, amount, serviceId) default: s.Fatalf("ERROR: unknown actor type %s", actorType) } @@ -333,15 +342,32 @@ func (s *suite) getConfigFileContent(amount int64, actorType, serviceId string) } func (s *suite) TheUserUnstakesAFromTheAccount(actorType string, accName string) { - args := []string{ - "tx", - actorType, - fmt.Sprintf("unstake-%s", actorType), - "--from", - accName, - keyRingFlag, - chainIdFlag, - "-y", + var args []string + + switch actorType { + case "supplier": + args = []string{ + "tx", + actorType, + fmt.Sprintf("unstake-%s", actorType), + accNameToAddrMap[accName], // supplier owner or operator address + "--from", + accName, + keyRingFlag, + chainIdFlag, + "-y", + } + default: + args = []string{ + "tx", + actorType, + fmt.Sprintf("unstake-%s", actorType), + "--from", + accName, + keyRingFlag, + chainIdFlag, + "-y", + } } res, err := s.pocketd.RunCommandOnHost("", args...) diff --git a/proto/poktroll/supplier/tx.proto b/proto/poktroll/supplier/tx.proto index ee44679b2..9d69fdd87 100644 --- a/proto/poktroll/supplier/tx.proto +++ b/proto/poktroll/supplier/tx.proto @@ -60,7 +60,7 @@ message MsgUnstakeSupplier { option (cosmos.msg.v1.signer) = "signer"; string signer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the message signer (i.e. owner or operator) - string address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the operator (i.e. provider, non-custodial) + string address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the operator (i.e. provider, non-custodial) } message MsgUnstakeSupplierResponse {} diff --git a/testutil/integration/app.go b/testutil/integration/app.go index 999949d9a..003886df7 100644 --- a/testutil/integration/app.go +++ b/testutil/integration/app.go @@ -529,8 +529,9 @@ func NewCompleteIntegrationApp(t *testing.T) *App { // Prepare the on-chain supplier supplierStake := types.NewCoin("upokt", math.NewInt(1000000)) defaultSupplier := sharedtypes.Supplier{ - Address: supplierAddr.String(), - Stake: &supplierStake, + OwnerAddress: supplierAddr.String(), + Address: supplierAddr.String(), + Stake: &supplierStake, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &defaultService, diff --git a/testutil/keeper/supplier.go b/testutil/keeper/supplier.go index cce5bfe73..bef17530d 100644 --- a/testutil/keeper/supplier.go +++ b/testutil/keeper/supplier.go @@ -32,6 +32,8 @@ import ( type SupplierModuleKeepers struct { *keeper.Keeper types.SharedKeeper + // Tracks the amount of funds returned to the supplier owner when the supplier is unbonded. + SupplierUnstakedFundsMap map[string]int64 } func SupplierKeeper(t testing.TB) (SupplierModuleKeepers, context.Context) { @@ -51,11 +53,18 @@ func SupplierKeeper(t testing.TB) (SupplierModuleKeepers, context.Context) { cdc := codec.NewProtoCodec(registry) authority := authtypes.NewModuleAddress(govtypes.ModuleName) + // Set a simple map to track the where the supplier stake is returned when + // the supplier is unbonded. + supplierUnstakedFundsMap := make(map[string]int64) + ctrl := gomock.NewController(t) mockBankKeeper := mocks.NewMockBankKeeper(ctrl) mockBankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), types.ModuleName, gomock.Any()).AnyTimes() - mockBankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, gomock.Any(), gomock.Any()).AnyTimes() mockBankKeeper.EXPECT().SpendableCoins(gomock.Any(), gomock.Any()).AnyTimes() + mockBankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, gomock.Any(), gomock.Any()).AnyTimes(). + Do(func(ctx context.Context, module string, addr sdk.AccAddress, coins sdk.Coins) { + supplierUnstakedFundsMap[addr.String()] += coins[0].Amount.Int64() + }) // Construct a real shared keeper. sharedKeeper := sharedkeeper.NewKeeper( @@ -95,8 +104,9 @@ func SupplierKeeper(t testing.TB) (SupplierModuleKeepers, context.Context) { serviceKeeper.SetService(ctx, sharedtypes.Service{Id: "svcId2"}) supplierModuleKeepers := SupplierModuleKeepers{ - Keeper: &supplierKeeper, - SharedKeeper: sharedKeeper, + Keeper: &supplierKeeper, + SharedKeeper: sharedKeeper, + SupplierUnstakedFundsMap: supplierUnstakedFundsMap, } return supplierModuleKeepers, ctx diff --git a/testutil/keeper/tokenomics.go b/testutil/keeper/tokenomics.go index a86f20c27..eabc675b9 100644 --- a/testutil/keeper/tokenomics.go +++ b/testutil/keeper/tokenomics.go @@ -123,8 +123,9 @@ func TokenomicsKeeperWithActorAddrs(t testing.TB) ( // Prepare the test supplier. supplier := sharedtypes.Supplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100000)}, + OwnerAddress: sample.AccAddress(), + Address: sample.AccAddress(), + Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100000)}, } ctrl := gomock.NewController(t) diff --git a/testutil/network/network.go b/testutil/network/network.go index aea39399f..d6fa0ae17 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -140,8 +140,9 @@ func DefaultSupplierModuleGenesisState(t *testing.T, n int) *suppliertypes.Genes svcId := fmt.Sprintf("svc%d", i) stake := sdk.NewCoin("upokt", math.NewInt(int64(i))) supplier := sharedtypes.Supplier{ - Address: sample.AccAddress(), - Stake: &stake, + OwnerAddress: sample.AccAddress(), + Address: sample.AccAddress(), + Stake: &stake, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &sharedtypes.Service{Id: svcId}, @@ -169,8 +170,9 @@ func SupplierModuleGenesisStateWithAddresses(t *testing.T, addresses []string) * state := suppliertypes.DefaultGenesis() for _, addr := range addresses { supplier := sharedtypes.Supplier{ - Address: addr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(10000)}, + OwnerAddress: sample.AccAddress(), + Address: addr, + Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(10000)}, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &sharedtypes.Service{Id: "svc1"}, diff --git a/x/supplier/config/supplier_configs_reader_test.go b/x/supplier/config/supplier_configs_reader_test.go index a2a51d04d..356b7844c 100644 --- a/x/supplier/config/supplier_configs_reader_test.go +++ b/x/supplier/config/supplier_configs_reader_test.go @@ -2,6 +2,7 @@ package config_test import ( "context" + "fmt" "testing" sdkerrors "cosmossdk.io/errors" @@ -10,12 +11,16 @@ import ( "github.com/gogo/status" "github.com/stretchr/testify/require" + _ "github.com/pokt-network/poktroll/pkg/polylog/polyzero" + "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/testutil/yaml" "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/supplier/config" ) func Test_ParseSupplierConfigs_Services(t *testing.T) { + operatorAddress := sample.AccAddress() + ownerAddress := sample.AccAddress() tests := []struct { desc string inputConfig string @@ -26,7 +31,9 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { // Valid Configs { desc: "valid full service config", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc @@ -35,10 +42,12 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: timeout: 10 - `, + `, ownerAddress, operatorAddress), expectedError: nil, expectedConfig: &config.SupplierStakeConfig{ - StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), + OwnerAddress: ownerAddress, + OperatorAddress: operatorAddress, + StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), Services: []*types.SupplierServiceConfig{ { Service: &types.Service{Id: "svc"}, @@ -60,17 +69,21 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { }, { desc: "valid service config without endpoint specific config", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc endpoints: - publicly_exposed_url: http://pokt.network:8081 rpc_type: json_rpc - `, + `, ownerAddress, operatorAddress), expectedError: nil, expectedConfig: &config.SupplierStakeConfig{ - StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), + OwnerAddress: ownerAddress, + OperatorAddress: operatorAddress, + StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), Services: []*types.SupplierServiceConfig{ { Service: &types.Service{Id: "svc"}, @@ -86,7 +99,9 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { }, { desc: "valid service config with empty endpoint specific config", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc @@ -94,10 +109,12 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { - publicly_exposed_url: http://pokt.network:8081 rpc_type: json_rpc config: - `, + `, ownerAddress, operatorAddress), expectedError: nil, expectedConfig: &config.SupplierStakeConfig{ - StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), + OwnerAddress: ownerAddress, + OperatorAddress: operatorAddress, + StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), Services: []*types.SupplierServiceConfig{ { Service: &types.Service{Id: "svc"}, @@ -114,7 +131,9 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { }, { desc: "valid service config with multiple endpoints", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc @@ -127,10 +146,12 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: timeout: 11 - `, + `, ownerAddress, operatorAddress), expectedError: nil, expectedConfig: &config.SupplierStakeConfig{ - StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), + OwnerAddress: ownerAddress, + OperatorAddress: operatorAddress, + StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), Services: []*types.SupplierServiceConfig{ { Service: &types.Service{Id: "svc"}, @@ -163,7 +184,9 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { { desc: "valid service config with multiple services", expectedError: nil, - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc1 @@ -178,9 +201,11 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: timeout: 10 - `, + `, ownerAddress, operatorAddress), expectedConfig: &config.SupplierStakeConfig{ - StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), + OwnerAddress: ownerAddress, + OperatorAddress: operatorAddress, + StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), Services: []*types.SupplierServiceConfig{ { Service: &types.Service{Id: "svc1"}, @@ -215,10 +240,88 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { }, }, }, + { + desc: "valid omitted operator address", + inputConfig: fmt.Sprintf(` + owner_address: %s + # omitted operator address + stake_amount: 1000upokt + services: + - service_id: svc + endpoints: + - publicly_exposed_url: http://pokt.network:8081 + rpc_type: json_rpc + config: + timeout: 10 + `, ownerAddress), + expectedError: nil, + expectedConfig: &config.SupplierStakeConfig{ + OwnerAddress: ownerAddress, + OperatorAddress: ownerAddress, + StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), + Services: []*types.SupplierServiceConfig{ + { + Service: &types.Service{Id: "svc"}, + Endpoints: []*types.SupplierEndpoint{ + { + Url: "http://pokt.network:8081", + RpcType: types.RPCType_JSON_RPC, + Configs: []*types.ConfigOption{ + { + Key: types.ConfigOptions_TIMEOUT, + Value: "10", + }, + }, + }, + }, + }, + }, + }, + }, + { + desc: "valid full service config", + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s + stake_amount: 1000upokt + services: + - service_id: svc + endpoints: + - publicly_exposed_url: http://pokt.network:8081 + rpc_type: json_rpc + config: + timeout: 10 + `, ownerAddress, ownerAddress), + expectedError: nil, + expectedConfig: &config.SupplierStakeConfig{ + OwnerAddress: ownerAddress, + OperatorAddress: ownerAddress, + StakeAmount: sdk.NewCoin("upokt", math.NewInt(1000)), + Services: []*types.SupplierServiceConfig{ + { + Service: &types.Service{Id: "svc"}, + Endpoints: []*types.SupplierEndpoint{ + { + Url: "http://pokt.network:8081", + RpcType: types.RPCType_JSON_RPC, + Configs: []*types.ConfigOption{ + { + Key: types.ConfigOptions_TIMEOUT, + Value: "10", + }, + }, + }, + }, + }, + }, + }, + }, // Invalid Configs { desc: "invalid service config without service ID", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - endpoints: @@ -226,12 +329,14 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: timeout: 10 - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigInvalidServiceId, }, { desc: "invalid service config with empty service ID", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: @@ -240,31 +345,37 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: timeout: 10 - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigInvalidServiceId, }, { desc: "invalid service config without endpoints", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigNoEndpoints, }, { desc: "invalid service config with empty endpoints", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc endpoints: - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigNoEndpoints, }, { desc: "invalid service config with unknown endpoint config key", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc @@ -273,12 +384,14 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: somekey: 10 - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigInvalidEndpointConfig, }, { desc: "invalid service config with unknown endpoint rpc type", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc @@ -287,12 +400,14 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: somerpc config: timeout: 10 - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigInvalidRPCType, }, { desc: "invalid service config with invalid endpoint url", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc @@ -301,7 +416,7 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: timeout: 10 - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigInvalidURL, }, { @@ -311,7 +426,9 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { }, { desc: "missing stake amount", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s services: - service_id: svc endpoints: @@ -319,12 +436,14 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: timeout: 10 - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigInvalidStake, }, { desc: "invalid stake denom", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000invalid services: - service_id: svc @@ -333,12 +452,14 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: timeout: 10 - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigInvalidStake, }, { desc: "negative stake amount", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: -1000upokt services: - service_id: svc @@ -347,12 +468,14 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: timeout: 10 - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigInvalidStake, }, { desc: "zero stake amount", - inputConfig: ` + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 0upokt services: - service_id: svc @@ -361,13 +484,60 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { rpc_type: json_rpc config: timeout: 10 - `, + `, ownerAddress, operatorAddress), expectedError: config.ErrSupplierConfigInvalidStake, }, + { + desc: "missing owner address", + inputConfig: fmt.Sprintf(` + # explictly omitted owner address + operator_address: %s + stake_amount: 1000upokt + services: + - service_id: svc + endpoints: + - publicly_exposed_url: http://pokt.network:8081 + rpc_type: json_rpc + config: + timeout: 10 + `, operatorAddress), + expectedError: config.ErrSupplierConfigInvalidOwnerAddress, + }, + { + desc: "invalid owner address", + inputConfig: fmt.Sprintf(` + owner_address: invalid_address + operator_address: %s + stake_amount: 1000upokt + services: + - service_id: svc + endpoints: + - publicly_exposed_url: http://pokt.network:8081 + rpc_type: json_rpc + config: + timeout: 10 + `, operatorAddress), + expectedError: config.ErrSupplierConfigInvalidOwnerAddress, + }, + { + desc: "invalid operator address", + inputConfig: fmt.Sprintf(` + owner_address: %s + operator_address: invalid_address + stake_amount: 1000upokt + services: + - service_id: svc + endpoints: + - publicly_exposed_url: http://pokt.network:8081 + rpc_type: json_rpc + config: + timeout: 10 + `, ownerAddress), + expectedError: config.ErrSupplierConfigInvalidOperatorAddress, + }, } ctx := context.Background() - for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { normalizedConfig := yaml.NormalizeYAMLIndentation(tt.inputConfig) diff --git a/x/supplier/keeper/msg_server_stake_supplier_test.go b/x/supplier/keeper/msg_server_stake_supplier_test.go index 1de18fe24..5f4350e36 100644 --- a/x/supplier/keeper/msg_server_stake_supplier_test.go +++ b/x/supplier/keeper/msg_server_stake_supplier_test.go @@ -19,24 +19,25 @@ func TestMsgServer_StakeSupplier_SuccessfulCreateAndUpdate(t *testing.T) { supplierModuleKeepers, ctx := keepertest.SupplierKeeper(t) srv := keeper.NewMsgServerImpl(*supplierModuleKeepers.Keeper) - // Generate an address for the supplier - supplierAddr := sample.AccAddress() + // Generate an owner and operator address for the supplier + ownerAddr := sample.AccAddress() + operatorAddr := sample.AccAddress() // Verify that the supplier does not exist yet - _, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, supplierAddr) + _, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, operatorAddr) require.False(t, isSupplierFound) // Prepare the stakeMsg - stakeMsg := stakeSupplierForServicesMsg(supplierAddr, 100, "svcId") + stakeMsg := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 100, "svcId") // Stake the supplier _, err := srv.StakeSupplier(ctx, stakeMsg) require.NoError(t, err) // Verify that the supplier exists - foundSupplier, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, supplierAddr) + foundSupplier, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, operatorAddr) require.True(t, isSupplierFound) - require.Equal(t, supplierAddr, foundSupplier.Address) + require.Equal(t, operatorAddr, foundSupplier.Address) require.Equal(t, int64(100), foundSupplier.Stake.Amount.Int64()) require.Len(t, foundSupplier.Services, 1) require.Equal(t, "svcId", foundSupplier.Services[0].Service.Id) @@ -44,78 +45,66 @@ func TestMsgServer_StakeSupplier_SuccessfulCreateAndUpdate(t *testing.T) { require.Equal(t, "http://localhost:8080", foundSupplier.Services[0].Endpoints[0].Url) // Prepare an updated supplier with a higher stake and a different URL for the service - updateMsg := stakeSupplierForServicesMsg(supplierAddr, 200, "svcId2") + updateMsg := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 200, "svcId2") + updateMsg.Services[0].Endpoints[0].Url = "http://localhost:8082" // Update the staked supplier _, err = srv.StakeSupplier(ctx, updateMsg) require.NoError(t, err) - foundSupplier, isSupplierFound = supplierModuleKeepers.GetSupplier(ctx, supplierAddr) + foundSupplier, isSupplierFound = supplierModuleKeepers.GetSupplier(ctx, operatorAddr) require.True(t, isSupplierFound) require.Equal(t, int64(200), foundSupplier.Stake.Amount.Int64()) require.Len(t, foundSupplier.Services, 1) require.Equal(t, "svcId2", foundSupplier.Services[0].Service.Id) require.Len(t, foundSupplier.Services[0].Endpoints, 1) - require.Equal(t, "http://localhost:8080", foundSupplier.Services[0].Endpoints[0].Url) + require.Equal(t, "http://localhost:8082", foundSupplier.Services[0].Endpoints[0].Url) } func TestMsgServer_StakeSupplier_FailRestakingDueToInvalidServices(t *testing.T) { supplierModuleKeepers, ctx := keepertest.SupplierKeeper(t) srv := keeper.NewMsgServerImpl(*supplierModuleKeepers.Keeper) - supplierAddr := sample.AccAddress() + // Generate an owner and operator address for the supplier + ownerAddr := sample.AccAddress() + operatorAddr := sample.AccAddress() // Prepare the supplier stake message - stakeMsg := stakeSupplierForServicesMsg(supplierAddr, 100, "svcId") + stakeMsg := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 100, "svcId") // Stake the supplier _, err := srv.StakeSupplier(ctx, stakeMsg) require.NoError(t, err) // Prepare the supplier stake message without any service endpoints - updateStakeMsg := &types.MsgStakeSupplier{ - Address: supplierAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, - Services: []*sharedtypes.SupplierServiceConfig{ - { - Service: &sharedtypes.Service{Id: "svcId"}, - Endpoints: []*sharedtypes.SupplierEndpoint{}, - }, - }, - } + updateStakeMsg := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 200, "svcId") + updateStakeMsg.Services[0].Endpoints = []*sharedtypes.SupplierEndpoint{} // Fail updating the supplier when the list of service endpoints is empty _, err = srv.StakeSupplier(ctx, updateStakeMsg) require.Error(t, err) // Verify the supplierFound still exists and is staked for svc1 - supplierFound, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, supplierAddr) + supplierFound, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, operatorAddr) require.True(t, isSupplierFound) - require.Equal(t, supplierAddr, supplierFound.Address) + require.Equal(t, operatorAddr, supplierFound.Address) require.Len(t, supplierFound.Services, 1) require.Equal(t, "svcId", supplierFound.Services[0].Service.Id) require.Len(t, supplierFound.Services[0].Endpoints, 1) require.Equal(t, "http://localhost:8080", supplierFound.Services[0].Endpoints[0].Url) // Prepare the supplier stake message with an invalid service ID - updateStakeMsg = &types.MsgStakeSupplier{ - Address: supplierAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, - Services: []*sharedtypes.SupplierServiceConfig{ - { - Service: &sharedtypes.Service{Id: "svc1 INVALID ! & *"}, - }, - }, - } + updateStakeMsg = stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 200, "svcId") + updateStakeMsg.Services[0].Service.Id = "svc1 INVALID ! & *" // Fail updating the supplier when the list of services is empty _, err = srv.StakeSupplier(ctx, updateStakeMsg) require.Error(t, err) // Verify the supplier still exists and is staked for svc1 - supplierFound, isSupplierFound = supplierModuleKeepers.GetSupplier(ctx, supplierAddr) + supplierFound, isSupplierFound = supplierModuleKeepers.GetSupplier(ctx, operatorAddr) require.True(t, isSupplierFound) - require.Equal(t, supplierAddr, supplierFound.Address) + require.Equal(t, operatorAddr, supplierFound.Address) require.Len(t, supplierFound.Services, 1) require.Equal(t, "svcId", supplierFound.Services[0].Service.Id) require.Len(t, supplierFound.Services[0].Endpoints, 1) @@ -126,26 +115,30 @@ func TestMsgServer_StakeSupplier_FailLoweringStake(t *testing.T) { supplierModuleKeepers, ctx := keepertest.SupplierKeeper(t) srv := keeper.NewMsgServerImpl(*supplierModuleKeepers.Keeper) - // Prepare the supplier - supplierAddr := sample.AccAddress() - stakeMsg := stakeSupplierForServicesMsg(supplierAddr, 100, "svcId") + // Generate an owner and operator address for the supplier + ownerAddr := sample.AccAddress() + operatorAddr := sample.AccAddress() + + // Prepare the supplier stake message + stakeMsg := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 100, "svcId") // Stake the supplier & verify that the supplier exists _, err := srv.StakeSupplier(ctx, stakeMsg) require.NoError(t, err) - _, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, supplierAddr) + _, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, operatorAddr) require.True(t, isSupplierFound) - // Prepare an updated supplier with a lower stake - updateMsg := stakeSupplierForServicesMsg(supplierAddr, 50, "svcId") + // Prepare an update supplier msg with a lower stake + updateMsg := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 50, "svcId") + updateMsg.Signer = operatorAddr // Verify that it fails _, err = srv.StakeSupplier(ctx, updateMsg) require.Error(t, err) // Verify that the supplier stake is unchanged - supplierFound, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, supplierAddr) + supplierFound, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, operatorAddr) require.True(t, isSupplierFound) require.Equal(t, int64(100), supplierFound.Stake.Amount.Int64()) require.Len(t, supplierFound.Services, 1) @@ -155,22 +148,129 @@ func TestMsgServer_StakeSupplier_FailWithNonExistingService(t *testing.T) { supplierModuleKeepers, ctx := keepertest.SupplierKeeper(t) srv := keeper.NewMsgServerImpl(*supplierModuleKeepers.Keeper) - // Prepare the supplier - supplierAddr := sample.AccAddress() - stakeMsg := stakeSupplierForServicesMsg(supplierAddr, 100, "newService") + // Generate an owner and operator address for the supplier + ownerAddr := sample.AccAddress() + operatorAddr := sample.AccAddress() + + // Prepare the supplier stake message with a non-existing service ID + stakeMsg := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 100, "newService") // Stake the supplier & verify that it fails because the service does not exist. _, err := srv.StakeSupplier(ctx, stakeMsg) require.ErrorIs(t, err, types.ErrSupplierServiceNotFound) } +func TestMsgServer_StakeSupplier_OperatorAuthorizations(t *testing.T) { + k, ctx := keepertest.SupplierKeeper(t) + srv := keeper.NewMsgServerImpl(*k.Keeper) + + // Generate an owner and operator address for the supplier + ownerAddr := sample.AccAddress() + operatorAddr := sample.AccAddress() + + // Stake using the operator address as the signer and verify that it succeeds. + stakeMsg := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 100, "svcId") + setStakeMsgSigner(stakeMsg, operatorAddr) + _, err := srv.StakeSupplier(ctx, stakeMsg) + require.NoError(t, err) + supplier, isSupplierFound := k.GetSupplier(ctx, operatorAddr) + require.True(t, isSupplierFound) + require.Equal(t, operatorAddr, supplier.Address) + require.Equal(t, ownerAddr, supplier.OwnerAddress) + + // Update the supplier using the operator address as the signer and verify that it succeeds. + stakeMsgUpdateUrl := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 200, "svcId") + operatorUpdatedServiceUrl := "http://localhost:8081" + stakeMsgUpdateUrl.Services[0].Endpoints[0].Url = operatorUpdatedServiceUrl + setStakeMsgSigner(stakeMsgUpdateUrl, operatorAddr) + _, err = srv.StakeSupplier(ctx, stakeMsgUpdateUrl) + require.NoError(t, err) + + // Check that the supplier was updated + foundSupplier, supplierFound := k.GetSupplier(ctx, operatorAddr) + require.True(t, supplierFound) + require.Equal(t, operatorUpdatedServiceUrl, foundSupplier.Services[0].Endpoints[0].Url) + + // Update the supplier URL by using the owner address as the singer and verify that it succeeds. + ownerUpdaterServiceUrl := "http://localhost:8082" + stakeMsgUpdateUrl.Services[0].Endpoints[0].Url = ownerUpdaterServiceUrl + stakeMsgUpdateUrl.Stake.Amount = math.NewInt(300) + setStakeMsgSigner(stakeMsgUpdateUrl, ownerAddr) + _, err = srv.StakeSupplier(ctx, stakeMsgUpdateUrl) + require.NoError(t, err) + + // Check that the supplier was updated + foundSupplier, supplierFound = k.GetSupplier(ctx, operatorAddr) + require.True(t, supplierFound) + require.Equal(t, ownerUpdaterServiceUrl, foundSupplier.Services[0].Endpoints[0].Url) + require.NotEqual(t, operatorUpdatedServiceUrl, foundSupplier.Services[0].Endpoints[0].Url) + + // Try updating the supplier's operator address using the old operator as a signer + // will create a new supplier. + stakeMsgUpdateOperator := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 300, "svcId") + newOperatorAddress := sample.AccAddress() + stakeMsgUpdateOperator.Address = newOperatorAddress + setStakeMsgSigner(stakeMsgUpdateOperator, operatorAddr) + _, err = srv.StakeSupplier(ctx, stakeMsgUpdateOperator) + require.NoError(t, err) + + // Check that the old supplier still exists. + oldSupplier, oldSupplierFound := k.GetSupplier(ctx, operatorAddr) + require.True(t, oldSupplierFound) + // Check that a supplier with the new operator address exists. + newSupplier, newSupplierFound := k.GetSupplier(ctx, newOperatorAddress) + require.True(t, newSupplierFound) + // Check that the old supplier is different from the new supplier. + require.NotEqual(t, oldSupplier.Address, newSupplier.Address) + + // Trying to update the supplier's operator address using the owner as a signer + // will create a new supplier. + newOperatorAddress = sample.AccAddress() + stakeMsgUpdateOperator.Address = newOperatorAddress + stakeMsgUpdateOperator.Stake.Amount = math.NewInt(400) + setStakeMsgSigner(stakeMsgUpdateOperator, ownerAddr) + _, err = srv.StakeSupplier(ctx, stakeMsgUpdateOperator) + require.NoError(t, err) + + // Check that the old supplier still exists. + oldSupplier, oldSupplierFound = k.GetSupplier(ctx, operatorAddr) + require.True(t, oldSupplierFound) + // Check that a supplier with the new operator address exists. + newSupplier, newSupplierFound = k.GetSupplier(ctx, newOperatorAddress) + require.True(t, newSupplierFound) + // Check that the old supplier is different from the new supplier. + require.NotEqual(t, oldSupplier.Address, newSupplier.Address) + + // Try updating the supplier's owner address using the operator as a signer + // and verify that it fails. + newOwnerAddress := sample.AccAddress() + stakeMsgUpdateOwner := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 500, "svcId") + stakeMsgUpdateOwner.OwnerAddress = newOwnerAddress + setStakeMsgSigner(stakeMsgUpdateOwner, operatorAddr) + _, err = srv.StakeSupplier(ctx, stakeMsgUpdateOwner) + require.ErrorIs(t, err, sharedtypes.ErrSharedUnauthorizedSupplierUpdate) + + // Update the supplier's owner address using the owner as a signer and verify that it succeeds. + setStakeMsgSigner(stakeMsgUpdateOwner, ownerAddr) + _, err = srv.StakeSupplier(ctx, stakeMsgUpdateOwner) + require.NoError(t, err) + + // Check that the supplier was updated. + foundSupplier, supplierFound = k.GetSupplier(ctx, operatorAddr) + require.True(t, supplierFound) + require.Equal(t, newOwnerAddress, foundSupplier.OwnerAddress) +} + func TestMsgServer_StakeSupplier_ActiveSupplier(t *testing.T) { supplierModuleKeepers, ctx := keepertest.SupplierKeeper(t) srv := keeper.NewMsgServerImpl(*supplierModuleKeepers.Keeper) + // Generate an owner and operator address for the supplier + ownerAddr := sample.AccAddress() + operatorAddr := sample.AccAddress() + // Prepare the supplier - supplierAddr := sample.AccAddress() - stakeMsg := stakeSupplierForServicesMsg(supplierAddr, 100, "svcId") + stakeMsg := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 100, "svcId") // Stake the supplier & verify that the supplier exists. _, err := srv.StakeSupplier(ctx, stakeMsg) @@ -180,7 +280,7 @@ func TestMsgServer_StakeSupplier_ActiveSupplier(t *testing.T) { currentHeight := sdkCtx.BlockHeight() sessionEndHeight := supplierModuleKeepers.SharedKeeper.GetSessionEndHeight(ctx, currentHeight) - foundSupplier, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, supplierAddr) + foundSupplier, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, operatorAddr) require.True(t, isSupplierFound) require.Equal(t, 1, len(foundSupplier.ServicesActivationHeightsMap)) @@ -199,13 +299,14 @@ func TestMsgServer_StakeSupplier_ActiveSupplier(t *testing.T) { ctx = keepertest.SetBlockHeight(ctx, sessionEndHeight+1) // Prepare the supplier stake message with a different service - updateMsg := stakeSupplierForServicesMsg(supplierAddr, 200, "svcId", "svcId2") + updateMsg := stakeSupplierForServicesMsg(ownerAddr, operatorAddr, 200, "svcId", "svcId2") + updateMsg.Signer = operatorAddr // Update the staked supplier _, err = srv.StakeSupplier(ctx, updateMsg) require.NoError(t, err) - foundSupplier, isSupplierFound = supplierModuleKeepers.GetSupplier(ctx, supplierAddr) + foundSupplier, isSupplierFound = supplierModuleKeepers.GetSupplier(ctx, operatorAddr) require.True(t, isSupplierFound) // The supplier should reference both services. @@ -230,7 +331,7 @@ func TestMsgServer_StakeSupplier_ActiveSupplier(t *testing.T) { // stakeSupplierForServicesMsg prepares and returns a MsgStakeSupplier that stakes // the given supplier address, stake amount, and service IDs. func stakeSupplierForServicesMsg( - supplierAddr string, + ownerAddr, operatorAddr string, amount int64, serviceIds ...string, ) *types.MsgStakeSupplier { @@ -249,8 +350,19 @@ func stakeSupplierForServicesMsg( } return &types.MsgStakeSupplier{ - Address: supplierAddr, - Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(amount)}, - Services: services, + Signer: ownerAddr, + OwnerAddress: ownerAddr, + Address: operatorAddr, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(amount)}, + Services: services, } } + +// setStakeMsgSigner sets the signer of the given MsgStakeSupplier to the given address +func setStakeMsgSigner( + msg *types.MsgStakeSupplier, + signer string, +) *types.MsgStakeSupplier { + msg.Signer = signer + return msg +} diff --git a/x/supplier/keeper/msg_server_unstake_supplier_test.go b/x/supplier/keeper/msg_server_unstake_supplier_test.go index 9e7cebb73..be4cccd94 100644 --- a/x/supplier/keeper/msg_server_unstake_supplier_test.go +++ b/x/supplier/keeper/msg_server_unstake_supplier_test.go @@ -54,7 +54,10 @@ func TestMsgServer_UnstakeSupplier_Success(t *testing.T) { require.True(t, isSupplierFound) // Initiate the supplier unstaking - unstakeMsg := &types.MsgUnstakeSupplier{Address: unstakingSupplierAddr} + unstakeMsg := &types.MsgUnstakeSupplier{ + Signer: unstakingSupplierAddr, + Address: unstakingSupplierAddr, + } _, err = srv.UnstakeSupplier(ctx, unstakeMsg) require.NoError(t, err) @@ -103,7 +106,10 @@ func TestMsgServer_UnstakeSupplier_CancelUnbondingIfRestaked(t *testing.T) { require.False(t, foundSupplier.IsUnbonding()) // Initiate the supplier unstaking - unstakeMsg := &types.MsgUnstakeSupplier{Address: supplierAddr} + unstakeMsg := &types.MsgUnstakeSupplier{ + Signer: supplierAddr, + Address: supplierAddr, + } _, err = srv.UnstakeSupplier(ctx, unstakeMsg) require.NoError(t, err) @@ -148,7 +154,10 @@ func TestMsgServer_UnstakeSupplier_FailIfNotStaked(t *testing.T) { require.False(t, isSupplierFound) // Initiate the supplier unstaking - unstakeMsg := &types.MsgUnstakeSupplier{Address: supplierAddr} + unstakeMsg := &types.MsgUnstakeSupplier{ + Signer: supplierAddr, + Address: supplierAddr, + } _, err := srv.UnstakeSupplier(ctx, unstakeMsg) require.Error(t, err) require.ErrorIs(t, err, types.ErrSupplierNotFound) @@ -171,7 +180,10 @@ func TestMsgServer_UnstakeSupplier_FailIfCurrentlyUnstaking(t *testing.T) { require.NoError(t, err) // Initiate the supplier unstaking - unstakeMsg := &types.MsgUnstakeSupplier{Address: supplierAddr} + unstakeMsg := &types.MsgUnstakeSupplier{ + Signer: supplierAddr, + Address: supplierAddr, + } _, err = srv.UnstakeSupplier(ctx, unstakeMsg) require.NoError(t, err) @@ -182,11 +194,57 @@ func TestMsgServer_UnstakeSupplier_FailIfCurrentlyUnstaking(t *testing.T) { require.ErrorIs(t, err, types.ErrSupplierIsUnstaking) } +func TestMsgServer_UnstakeSupplier_OperatorCanUnstake(t *testing.T) { + supplierModuleKeepers, ctx := keepertest.SupplierKeeper(t) + srv := keeper.NewMsgServerImpl(*supplierModuleKeepers.Keeper) + + // Generate an address for the supplier + ownerAddr := sample.AccAddress() + supplierAddr := sample.AccAddress() + + // Stake the supplier + initialStake := int64(100) + stakeMsg := createStakeMsg(ownerAddr, initialStake) + stakeMsg.Address = supplierAddr + _, err := srv.StakeSupplier(ctx, stakeMsg) + require.NoError(t, err) + + // Initiate the supplier unstaking + unstakeMsg := &types.MsgUnstakeSupplier{ + Signer: supplierAddr, + Address: supplierAddr, + } + _, err = srv.UnstakeSupplier(ctx, unstakeMsg) + require.NoError(t, err) + + // Make sure the supplier entered the unbonding period + foundSupplier, isSupplierFound := supplierModuleKeepers.GetSupplier(ctx, supplierAddr) + require.True(t, isSupplierFound) + require.True(t, foundSupplier.IsUnbonding()) + + // Move block height to the end of the unbonding period + sharedParams := supplierModuleKeepers.SharedKeeper.GetParams(ctx) + unbondingHeight := shared.GetSupplierUnbondingHeight(&sharedParams, &foundSupplier) + ctx = keepertest.SetBlockHeight(ctx, int64(unbondingHeight)) + + // Ensure that the initial stake is not returned to the owner yet + require.Equal(t, int64(0), supplierModuleKeepers.SupplierUnstakedFundsMap[ownerAddr]) + + // Run the endblocker to unbond suppliers + err = supplierModuleKeepers.EndBlockerUnbondSuppliers(ctx) + require.NoError(t, err) + + // Ensure that the initial stake is returned to the owner + require.Equal(t, initialStake, supplierModuleKeepers.SupplierUnstakedFundsMap[ownerAddr]) +} + func createStakeMsg(supplierAddr string, stakeAmount int64) *types.MsgStakeSupplier { initialStake := sdk.NewCoin("upokt", math.NewInt(stakeAmount)) return &types.MsgStakeSupplier{ - Address: supplierAddr, - Stake: &initialStake, + Signer: supplierAddr, + OwnerAddress: supplierAddr, + Address: supplierAddr, + Stake: &initialStake, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &sharedtypes.Service{ diff --git a/x/supplier/module/tx_stake_supplier_test.go b/x/supplier/module/tx_stake_supplier_test.go index d6e7123b6..3cac27cf6 100644 --- a/x/supplier/module/tx_stake_supplier_test.go +++ b/x/supplier/module/tx_stake_supplier_test.go @@ -14,6 +14,7 @@ import ( "google.golang.org/grpc/status" "github.com/pokt-network/poktroll/testutil/network" + "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/testutil/yaml" supplier "github.com/pokt-network/poktroll/x/supplier/module" "github.com/pokt-network/poktroll/x/supplier/types" @@ -27,10 +28,10 @@ func TestCLI_StakeSupplier(t *testing.T) { // Create a keyring and add an account for the supplier to be staked kr := ctx.Keyring accounts := testutil.CreateKeyringAccounts(t, kr, 1) - supplierAccount := accounts[0] + ownerAccount := accounts[0] // Initialize the Supplier Account by sending it some funds from the validator account that is part of genesis - network.InitAccount(t, net, supplierAccount.Address) + network.InitAccount(t, net, ownerAccount.Address) // Update the context with the new keyring ctx = ctx.WithKeyring(kr) @@ -42,101 +43,126 @@ func TestCLI_StakeSupplier(t *testing.T) { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, math.NewInt(10))).String()), } - defaultConfig := ` + defaultConfig := fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc1 endpoints: - publicly_exposed_url: http://pokt.network:8081 rpc_type: json_rpc - ` + `, ownerAccount.Address.String(), sample.AccAddress()) tests := []struct { - desc string - address string - config string - expectedErr *sdkerrors.Error + desc string + ownerAddress string + config string + expectedErr *sdkerrors.Error }{ // Happy Paths { - desc: "stake supplier: valid", - address: supplierAccount.Address.String(), - config: defaultConfig, + desc: "stake supplier: valid", + ownerAddress: ownerAccount.Address.String(), + config: defaultConfig, + }, + { + desc: "stake supplier: valid, omitted operator address", + ownerAddress: ownerAccount.Address.String(), + config: fmt.Sprintf(` + owner_address: %s + stake_amount: 1000upokt + services: + - service_id: svc1 + endpoints: + - publicly_exposed_url: http://pokt.network:8081 + rpc_type: json_rpc + `, ownerAccount.Address.String()), }, // Error Paths - Address Related { desc: "stake supplier: missing address", - // address: "explicitly missing", + // ownerAddress: "explicitly missing", expectedErr: types.ErrSupplierInvalidAddress, config: defaultConfig, }, { - desc: "stake supplier: invalid address", - address: "invalid", - expectedErr: types.ErrSupplierInvalidAddress, - config: defaultConfig, + desc: "stake supplier: invalid address", + ownerAddress: "invalid", + expectedErr: types.ErrSupplierInvalidAddress, + config: defaultConfig, }, // Error Paths - Stake Related { - desc: "stake supplier: missing stake", - address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidStake, - config: ` + desc: "stake supplier: missing stake", + ownerAddress: ownerAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidStake, + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s # explicitly omitted stake services: - service_id: svc1 endpoints: - publicly_exposed_url: http://pokt.network:8081 rpc_type: json_rpc - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "stake supplier: invalid stake denom", - address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidStake, - config: ` + desc: "stake supplier: invalid stake denom", + ownerAddress: ownerAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidStake, + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000invalid services: - service_id: svc1 endpoints: - publicly_exposed_url: http://pokt.network:8081 rpc_type: json_rpc - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "stake supplier: invalid stake amount (zero)", - address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidStake, - config: ` + desc: "stake supplier: invalid stake amount (zero)", + ownerAddress: ownerAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidStake, + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 0upokt services: - service_id: svc1 endpoints: - publicly_exposed_url: http://pokt.network:8081 rpc_type: json_rpc - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "stake supplier: invalid stake amount (negative)", - address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidStake, - config: ` + desc: "stake supplier: invalid stake amount (negative)", + ownerAddress: ownerAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidStake, + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: -1000upokt services: - service_id: svc1 endpoints: - publicly_exposed_url: http://pokt.network:8081 rpc_type: json_rpc - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, // Happy Paths - Service Related { - desc: "services_test: valid multiple services", - address: supplierAccount.Address.String(), - config: ` + desc: "services_test: valid multiple services", + ownerAddress: ownerAccount.Address.String(), + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc1 @@ -147,93 +173,109 @@ func TestCLI_StakeSupplier(t *testing.T) { endpoints: - publicly_exposed_url: http://pokt.network:8082 rpc_type: json_rpc - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "services_test: valid localhost", - address: supplierAccount.Address.String(), - config: ` + desc: "services_test: valid localhost", + ownerAddress: ownerAccount.Address.String(), + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc1 endpoints: - publicly_exposed_url: http://127.0.0.1:8082 rpc_type: json_rpc - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "services_test: valid loopback", - address: supplierAccount.Address.String(), - config: ` + desc: "services_test: valid loopback", + ownerAddress: ownerAccount.Address.String(), + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc1 endpoints: - publicly_exposed_url: http://localhost:8082 rpc_type: json_rpc - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "services_test: valid without a port", - address: supplierAccount.Address.String(), - config: ` + desc: "services_test: valid without a port", + ownerAddress: ownerAccount.Address.String(), + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc1 endpoints: - publicly_exposed_url: http://pokt.network rpc_type: json_rpc - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, // Error Paths - Service Related { - desc: "services_test: invalid services (missing argument)", - address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidServiceConfig, + desc: "services_test: invalid services (missing argument)", + ownerAddress: ownerAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidServiceConfig, // servicesString explicitly omitted - config: ` + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "services_test: invalid services (empty string)", - address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidServiceConfig, - config: ` + desc: "services_test: invalid services (empty string)", + ownerAddress: ownerAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidServiceConfig, + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "services_test: invalid URL", - address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidServiceConfig, - config: ` + desc: "services_test: invalid URL", + ownerAddress: ownerAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidServiceConfig, + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc1 endpoints: - publicly_exposed_url: bad_url rpc_type: json_rpc - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "services_test: missing URLs", - address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidServiceConfig, - config: ` + desc: "services_test: missing URLs", + ownerAddress: ownerAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidServiceConfig, + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc1 - service_id: svc2 - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "services_test: missing service IDs", - address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidServiceConfig, - config: ` + desc: "services_test: missing service IDs", + ownerAddress: ownerAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidServiceConfig, + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - endpoints: @@ -242,19 +284,21 @@ func TestCLI_StakeSupplier(t *testing.T) { - endpoints: - publicly_exposed_url: localhost:8082 rpc_type: json_rpc - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, { - desc: "services_test: missing rpc type", - address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidServiceConfig, - config: ` + desc: "services_test: missing rpc type", + ownerAddress: ownerAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidServiceConfig, + config: fmt.Sprintf(` + owner_address: %s + operator_address: %s stake_amount: 1000upokt services: - service_id: svc1 endpoints: - publicly_exposed_url: localhost:8082 - `, + `, ownerAccount.Address.String(), sample.AccAddress()), }, } @@ -270,7 +314,7 @@ func TestCLI_StakeSupplier(t *testing.T) { // Prepare the arguments for the CLI command args := []string{ fmt.Sprintf("--config=%s", configPath), - fmt.Sprintf("--%s=%s", flags.FlagFrom, test.address), + fmt.Sprintf("--%s=%s", flags.FlagFrom, test.ownerAddress), } args = append(args, commonArgs...) diff --git a/x/supplier/module/tx_unstake_supplier_test.go b/x/supplier/module/tx_unstake_supplier_test.go index 29a42ba99..4b438c89a 100644 --- a/x/supplier/module/tx_unstake_supplier_test.go +++ b/x/supplier/module/tx_unstake_supplier_test.go @@ -25,11 +25,14 @@ func TestCLI_UnstakeSupplier(t *testing.T) { // Create a keyring and add an account for the supplier to be unstaked kr := ctx.Keyring - accounts := testutil.CreateKeyringAccounts(t, kr, 1) - supplierAccount := accounts[0] + accounts := testutil.CreateKeyringAccounts(t, kr, 2) + operatorAccount := accounts[0] + ownerAccount := accounts[1] - // Initialize the Supplier Account by sending it some funds from the validator account that is part of genesis - network.InitAccount(t, net, supplierAccount.Address) + // Initialize the Supplier operator account by sending it some funds from the + // validator account that is part of genesis + network.InitAccountWithSequence(t, net, operatorAccount.Address, 1) + network.InitAccountWithSequence(t, net, ownerAccount.Address, 2) // Update the context with the new keyring ctx = ctx.WithKeyring(kr) @@ -42,24 +45,45 @@ func TestCLI_UnstakeSupplier(t *testing.T) { } tests := []struct { - desc string - address string - expectedErr *sdkerrors.Error + desc string + signerAddress string + operatorAddress string + expectedErr *sdkerrors.Error }{ { - desc: "unstake supplier: valid", - address: supplierAccount.Address.String(), + desc: "owner unstake supplier: valid", + signerAddress: ownerAccount.Address.String(), + operatorAddress: operatorAccount.Address.String(), }, { - desc: "unstake supplier: missing address", - // address: supplierAccount.Address.String(), - expectedErr: types.ErrSupplierInvalidAddress, + desc: "operator unstake supplier: valid", + signerAddress: operatorAccount.Address.String(), + operatorAddress: operatorAccount.Address.String(), + }, + { + desc: "unstake supplier: missing singer address", + // signerAddress: ownerAccount.Address.String(), + operatorAddress: operatorAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidAddress, }, { - desc: "unstake supplier: invalid address", - address: "invalid", + desc: "unstake supplier: invalid signer address", + signerAddress: "invalid", + operatorAddress: operatorAccount.Address.String(), + expectedErr: types.ErrSupplierInvalidAddress, + }, + { + desc: "unstake supplier: missing operator address", + signerAddress: ownerAccount.Address.String(), + // operatorAddress: operatorAccount.Address.String(), expectedErr: types.ErrSupplierInvalidAddress, }, + { + desc: "unstake supplier: invalid operator address", + signerAddress: ownerAccount.Address.String(), + operatorAddress: "invalid", + expectedErr: types.ErrSupplierInvalidAddress, + }, } // Run the tests @@ -70,7 +94,8 @@ func TestCLI_UnstakeSupplier(t *testing.T) { // Prepare the arguments for the CLI command args := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, test.address), + test.operatorAddress, + fmt.Sprintf("--%s=%s", flags.FlagFrom, test.signerAddress), } args = append(args, commonArgs...) diff --git a/x/supplier/types/message_stake_supplier_test.go b/x/supplier/types/message_stake_supplier_test.go index 4d6fe5bb4..cf92ba3a7 100644 --- a/x/supplier/types/message_stake_supplier_test.go +++ b/x/supplier/types/message_stake_supplier_test.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + "github.com/pokt-network/poktroll/app/volatile" "github.com/pokt-network/poktroll/testutil/sample" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -27,7 +28,11 @@ func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { Configs: make([]*sharedtypes.ConfigOption, 0), }, }, - }} + }, + } + + ownerAddress := sample.AccAddress() + operatorAddress := sample.AccAddress() tests := []struct { desc string @@ -36,61 +41,173 @@ func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { }{ // address related tests { - desc: "invalid address - nil stake", + desc: "valid same owner and operator address", msg: MsgStakeSupplier{ - Address: "invalid_address", - // Stake explicitly omitted + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: ownerAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, + Services: defaultServicesList, + }, + }, + { + desc: "valid different owner and operator address", + msg: MsgStakeSupplier{ + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, + Services: defaultServicesList, + }, + }, + { + desc: "valid signer is operator address", + msg: MsgStakeSupplier{ + Signer: operatorAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, + Services: defaultServicesList, + }, + }, + { + desc: "valid signer is neither the operator nor the owner", + msg: MsgStakeSupplier{ + Signer: sample.AccAddress(), + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, + Services: defaultServicesList, + }, + }, + { + desc: "invalid operator address", + msg: MsgStakeSupplier{ + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: "invalid_address", + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, + Services: defaultServicesList, + }, + expectedErr: ErrSupplierInvalidAddress, + }, + { + desc: "invalid owner address", + msg: MsgStakeSupplier{ + Signer: ownerAddress, + OwnerAddress: "invalid_address", + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, + Services: defaultServicesList, + }, + expectedErr: ErrSupplierInvalidAddress, + }, + { + desc: "invalid signer address", + msg: MsgStakeSupplier{ + Signer: "invalid_address", + OwnerAddress: ownerAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(0)}, + Services: defaultServicesList, + }, + expectedErr: ErrSupplierInvalidAddress, + }, + { + desc: "missing owner address", + msg: MsgStakeSupplier{ + Signer: ownerAddress, + // OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, + Services: defaultServicesList, + }, + expectedErr: ErrSupplierInvalidAddress, + }, + { + desc: "missing operator address", + msg: MsgStakeSupplier{ + Signer: ownerAddress, + OwnerAddress: ownerAddress, + // Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(0)}, Services: defaultServicesList, }, expectedErr: ErrSupplierInvalidAddress, }, + { + desc: "missing signer address", + msg: MsgStakeSupplier{ + // Signer: ownerAddress, + OwnerAddress: ownerAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(0)}, + Services: defaultServicesList, + }, + expectedErr: ErrSupplierInvalidAddress, + }, // stake related tests { - desc: "valid address - nil stake", + desc: "valid stake", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - // Stake explicitly omitted - Services: defaultServicesList, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, + Services: defaultServicesList, }, - expectedErr: ErrSupplierInvalidStake, - }, { - desc: "valid address - valid stake", + }, + { + desc: "invalid stake - missing stake", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + // Stake explicitly omitted Services: defaultServicesList, }, - }, { - desc: "valid address - zero stake", + expectedErr: ErrSupplierInvalidStake, + }, + { + desc: "invalid stake - zero amount", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(0)}, - Services: defaultServicesList, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(0)}, + Services: defaultServicesList, }, expectedErr: ErrSupplierInvalidStake, - }, { - desc: "valid address - negative stake", + }, + { + desc: "invalid stake - negative amount", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(-100)}, - Services: defaultServicesList, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(-100)}, + Services: defaultServicesList, }, expectedErr: ErrSupplierInvalidStake, - }, { - desc: "valid address - invalid stake denom", + }, + { + desc: "invalid stake - invalid denom", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "invalid", Amount: math.NewInt(100)}, - Services: defaultServicesList, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: "invalid", Amount: math.NewInt(100)}, + Services: defaultServicesList, }, expectedErr: ErrSupplierInvalidStake, - }, { - desc: "valid address - invalid stake missing denom", + }, + { + desc: "invalid stake - missing denom", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "", Amount: math.NewInt(100)}, - Services: defaultServicesList, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: "", Amount: math.NewInt(100)}, + Services: defaultServicesList, }, expectedErr: ErrSupplierInvalidStake, }, @@ -99,8 +216,10 @@ func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { { desc: "valid service configs - multiple services", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &sharedtypes.Service{ @@ -132,8 +251,10 @@ func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { { desc: "invalid service configs - omitted", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, // Services explicitly omitted }, expectedErr: ErrSupplierInvalidServiceConfig, @@ -141,17 +262,21 @@ func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { { desc: "invalid service configs - empty", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, - Services: []*sharedtypes.SupplierServiceConfig{}, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, + Services: []*sharedtypes.SupplierServiceConfig{}, }, expectedErr: ErrSupplierInvalidServiceConfig, }, { desc: "invalid service configs - invalid service ID that's too long", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &sharedtypes.Service{ @@ -172,8 +297,10 @@ func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { { desc: "invalid service configs - invalid service Name that's too long", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &sharedtypes.Service{ @@ -195,8 +322,10 @@ func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { { desc: "invalid service configs - invalid service ID that contains invalid characters", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &sharedtypes.Service{ @@ -217,8 +346,10 @@ func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { { desc: "invalid service configs - missing url", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &sharedtypes.Service{ @@ -240,8 +371,10 @@ func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { { desc: "invalid service configs - invalid url", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &sharedtypes.Service{ @@ -263,8 +396,10 @@ func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { { desc: "invalid service configs - missing rpc type", msg: MsgStakeSupplier{ - Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Signer: ownerAddress, + OwnerAddress: ownerAddress, + Address: operatorAddress, + Stake: &sdk.Coin{Denom: volatile.DenomuPOKT, Amount: math.NewInt(100)}, Services: []*sharedtypes.SupplierServiceConfig{ { Service: &sharedtypes.Service{ diff --git a/x/supplier/types/message_unstake_supplier_test.go b/x/supplier/types/message_unstake_supplier_test.go index b99a9186e..6ecb26642 100644 --- a/x/supplier/types/message_unstake_supplier_test.go +++ b/x/supplier/types/message_unstake_supplier_test.go @@ -9,25 +9,55 @@ import ( ) func TestMsgUnstakeSupplier_ValidateBasic(t *testing.T) { + signerAddress := sample.AccAddress() + operatorAddress := sample.AccAddress() tests := []struct { desc string msg MsgUnstakeSupplier expectedErr error }{ { - desc: "invalid address", + desc: "invalid operator address", msg: MsgUnstakeSupplier{ + Signer: signerAddress, Address: "invalid_address", }, expectedErr: ErrSupplierInvalidAddress, - }, { - desc: "missing address", - msg: MsgUnstakeSupplier{}, + }, + { + desc: "missing operator address", + msg: MsgUnstakeSupplier{ + Signer: signerAddress, + }, + expectedErr: ErrSupplierInvalidAddress, + }, + { + desc: "invalid signer address", + msg: MsgUnstakeSupplier{ + Signer: "invalid_address", + Address: operatorAddress, + }, + expectedErr: ErrSupplierInvalidAddress, + }, + { + desc: "missing signer address", + msg: MsgUnstakeSupplier{ + Address: operatorAddress, + }, expectedErr: ErrSupplierInvalidAddress, - }, { - desc: "valid address", + }, + { + desc: "valid message", + msg: MsgUnstakeSupplier{ + Signer: signerAddress, + Address: operatorAddress, + }, + }, + { + desc: "valid message - same signer and operator addresses", msg: MsgUnstakeSupplier{ - Address: sample.AccAddress(), + Signer: operatorAddress, + Address: operatorAddress, }, }, } diff --git a/x/supplier/types/tx.pb.go b/x/supplier/types/tx.pb.go index 45cb59c25..d7031afc5 100644 --- a/x/supplier/types/tx.pb.go +++ b/x/supplier/types/tx.pb.go @@ -241,7 +241,7 @@ var xxx_messageInfo_MsgStakeSupplierResponse proto.InternalMessageInfo type MsgUnstakeSupplier struct { Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` - Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` } func (m *MsgUnstakeSupplier) Reset() { *m = MsgUnstakeSupplier{} } @@ -339,43 +339,44 @@ func init() { func init() { proto.RegisterFile("poktroll/supplier/tx.proto", fileDescriptor_63b974929807ef57) } var fileDescriptor_63b974929807ef57 = []byte{ - // 574 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xbf, 0x8f, 0x12, 0x41, - 0x18, 0x65, 0x41, 0x50, 0x86, 0xbb, 0x9c, 0x37, 0xb9, 0xe4, 0x96, 0x8d, 0xae, 0x84, 0x8b, 0x86, - 0x60, 0xd8, 0x11, 0x4c, 0xae, 0xb8, 0x68, 0x21, 0x57, 0x1a, 0x12, 0x03, 0xb1, 0xb1, 0xf0, 0x32, - 0xc0, 0x38, 0x6c, 0x80, 0x9d, 0xcd, 0xcc, 0xc0, 0xdd, 0x75, 0xc6, 0xc6, 0xc4, 0xca, 0x3f, 0xc3, - 0x92, 0xc2, 0x42, 0x2b, 0xdb, 0x2b, 0x2f, 0x56, 0x56, 0xc6, 0x40, 0xc1, 0xbf, 0x61, 0x76, 0x77, - 0x06, 0xe4, 0x87, 0x72, 0xf1, 0x1a, 0x60, 0xe7, 0xbd, 0xf7, 0x7d, 0xef, 0x7b, 0xf3, 0x2d, 0xc0, - 0xf2, 0x59, 0x57, 0x72, 0xd6, 0xeb, 0x21, 0x31, 0xf0, 0xfd, 0x9e, 0x4b, 0x38, 0x92, 0x67, 0x8e, - 0xcf, 0x99, 0x64, 0x70, 0x57, 0x63, 0x8e, 0xc6, 0xac, 0x5d, 0xdc, 0x77, 0x3d, 0x86, 0xc2, 0xcf, - 0x88, 0x65, 0xed, 0xb7, 0x98, 0xe8, 0x33, 0x81, 0xfa, 0x82, 0xa2, 0x61, 0x39, 0xf8, 0x52, 0x40, - 0x36, 0x02, 0x4e, 0xc2, 0x27, 0x14, 0x3d, 0x28, 0x68, 0x8f, 0x32, 0xca, 0xa2, 0xf3, 0xe0, 0x97, - 0x3a, 0xb5, 0x55, 0xa5, 0x26, 0x16, 0x04, 0x0d, 0xcb, 0x4d, 0x22, 0x71, 0x19, 0xb5, 0x98, 0xeb, - 0x69, 0x7c, 0xd5, 0xab, 0x8f, 0x39, 0xee, 0xeb, 0xaa, 0x77, 0xe7, 0x78, 0x07, 0x73, 0xd2, 0x46, - 0x82, 0xf0, 0xa1, 0xdb, 0x22, 0x11, 0x9c, 0xff, 0x66, 0x80, 0x9d, 0x9a, 0xa0, 0x2f, 0xfd, 0x36, - 0x96, 0xe4, 0x45, 0x28, 0x84, 0x87, 0x20, 0x8d, 0x07, 0xb2, 0xc3, 0xb8, 0x2b, 0xcf, 0x4d, 0x23, - 0x67, 0x14, 0xd2, 0x55, 0xf3, 0xfb, 0xe7, 0xd2, 0x9e, 0x72, 0xfb, 0xac, 0xdd, 0xe6, 0x44, 0x88, - 0x86, 0xe4, 0xae, 0x47, 0xeb, 0x73, 0x2a, 0x7c, 0x02, 0x52, 0x51, 0x6b, 0x33, 0x9e, 0x33, 0x0a, - 0x99, 0x4a, 0xd6, 0x59, 0xc9, 0xca, 0x89, 0x5a, 0x54, 0xd3, 0x17, 0x3f, 0xef, 0xc5, 0x3e, 0x4d, - 0x47, 0x45, 0xa3, 0xae, 0x34, 0x47, 0x87, 0xef, 0xa6, 0xa3, 0xe2, 0xbc, 0xda, 0x87, 0xe9, 0xa8, - 0x78, 0x30, 0xf3, 0x7e, 0x36, 0x9f, 0x6e, 0xc9, 0x6d, 0x3e, 0x0b, 0xf6, 0x97, 0x8e, 0xea, 0x44, - 0xf8, 0xcc, 0x13, 0x24, 0xff, 0x35, 0x0e, 0x6e, 0xd7, 0x04, 0x6d, 0x48, 0xdc, 0x25, 0x0d, 0xa5, - 0x87, 0x8f, 0x40, 0x4a, 0xb8, 0xd4, 0x23, 0x7c, 0xe3, 0x68, 0x8a, 0x07, 0x9f, 0x82, 0x6d, 0x76, - 0xea, 0x11, 0x7e, 0x82, 0x23, 0x38, 0x1c, 0xef, 0x5f, 0xc2, 0xad, 0x90, 0xae, 0xce, 0x60, 0x05, - 0xdc, 0xd4, 0xc2, 0xc4, 0x06, 0xa1, 0x26, 0x42, 0x04, 0x92, 0x22, 0x70, 0x6d, 0xde, 0x50, 0x49, - 0x2a, 0x7a, 0xb0, 0x05, 0x8e, 0xda, 0x02, 0xe7, 0x98, 0xb9, 0x5e, 0x3d, 0xe2, 0xc1, 0x2a, 0xb8, - 0xa5, 0x2e, 0x56, 0x98, 0xc9, 0x5c, 0xa2, 0x90, 0xa9, 0x3c, 0xf8, 0x23, 0xfd, 0xf0, 0xe6, 0x1d, - 0x1d, 0x41, 0x23, 0x22, 0x1e, 0x33, 0xef, 0x8d, 0x4b, 0xeb, 0x33, 0xdd, 0x51, 0x26, 0xb8, 0x01, - 0x35, 0x74, 0xde, 0x02, 0xe6, 0x72, 0x74, 0xb3, 0x5c, 0xdf, 0x1b, 0x00, 0x06, 0x99, 0x7b, 0xe2, - 0x9a, 0xc9, 0xfe, 0x47, 0x34, 0x8b, 0x2e, 0xef, 0x00, 0x6b, 0xd5, 0x88, 0xf6, 0x59, 0xf9, 0x12, - 0x07, 0x89, 0x9a, 0xa0, 0xf0, 0x35, 0xd8, 0x5a, 0x58, 0xf0, 0xfc, 0x9a, 0xc5, 0x5c, 0xda, 0x21, - 0xab, 0xb8, 0x99, 0xa3, 0xfb, 0x40, 0x0c, 0xb6, 0x17, 0x77, 0xec, 0x60, 0xbd, 0x78, 0x81, 0x64, - 0x3d, 0xbc, 0x02, 0x69, 0xd6, 0x82, 0x82, 0x9d, 0xe5, 0xb8, 0xef, 0xff, 0xc5, 0xe1, 0x22, 0xcd, - 0x2a, 0x5d, 0x89, 0xa6, 0x1b, 0x59, 0xc9, 0xb7, 0xc1, 0x5b, 0x59, 0x7d, 0x7e, 0x31, 0xb6, 0x8d, - 0xcb, 0xb1, 0x6d, 0xfc, 0x1a, 0xdb, 0xc6, 0xc7, 0x89, 0x1d, 0xbb, 0x9c, 0xd8, 0xb1, 0x1f, 0x13, - 0x3b, 0xf6, 0xaa, 0x4c, 0x5d, 0xd9, 0x19, 0x34, 0x9d, 0x16, 0xeb, 0xa3, 0xa0, 0x72, 0xc9, 0x23, - 0xf2, 0x94, 0xf1, 0x2e, 0x5a, 0xf7, 0xb2, 0xca, 0x73, 0x9f, 0x88, 0x66, 0x2a, 0xfc, 0xaf, 0x79, - 0xfc, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x5c, 0x81, 0xd3, 0xc0, 0x58, 0x05, 0x00, 0x00, + // 579 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x3f, 0x8f, 0x12, 0x4f, + 0x18, 0x66, 0xe1, 0x07, 0x3f, 0x19, 0xee, 0x72, 0xde, 0xe4, 0x92, 0x5b, 0x36, 0xba, 0x12, 0x2e, + 0x1a, 0x82, 0x61, 0x47, 0x30, 0xb9, 0xe2, 0xa2, 0x85, 0x5c, 0x69, 0x48, 0x0c, 0xc4, 0xc6, 0xc2, + 0xcb, 0x00, 0xe3, 0xb0, 0x01, 0x76, 0x36, 0x33, 0x03, 0x77, 0xd7, 0x19, 0x1b, 0x13, 0x2b, 0x3f, + 0x86, 0x25, 0x85, 0x85, 0x56, 0xb6, 0x57, 0x5e, 0xac, 0xac, 0x8c, 0x81, 0x82, 0xaf, 0x61, 0x76, + 0x77, 0x06, 0x8e, 0x3f, 0x0a, 0x89, 0x0d, 0xb0, 0xf3, 0x3c, 0xcf, 0xfb, 0x3e, 0xef, 0x33, 0xef, + 0x02, 0x2c, 0x9f, 0x75, 0x25, 0x67, 0xbd, 0x1e, 0x12, 0x03, 0xdf, 0xef, 0xb9, 0x84, 0x23, 0x79, + 0xe1, 0xf8, 0x9c, 0x49, 0x06, 0xf7, 0x35, 0xe6, 0x68, 0xcc, 0xda, 0xc7, 0x7d, 0xd7, 0x63, 0x28, + 0xfc, 0x8c, 0x58, 0xd6, 0x61, 0x8b, 0x89, 0x3e, 0x13, 0xa8, 0x2f, 0x28, 0x1a, 0x96, 0x83, 0x2f, + 0x05, 0x64, 0x23, 0xe0, 0x2c, 0x7c, 0x42, 0xd1, 0x83, 0x82, 0x0e, 0x28, 0xa3, 0x2c, 0x3a, 0x0f, + 0x7e, 0xa9, 0x53, 0x5b, 0x55, 0x6a, 0x62, 0x41, 0xd0, 0xb0, 0xdc, 0x24, 0x12, 0x97, 0x51, 0x8b, + 0xb9, 0x9e, 0xc6, 0x57, 0xbd, 0xfa, 0x98, 0xe3, 0xbe, 0xae, 0x7a, 0x77, 0x8e, 0x77, 0x30, 0x27, + 0x6d, 0x24, 0x08, 0x1f, 0xba, 0x2d, 0x12, 0xc1, 0xf9, 0x6f, 0x06, 0xd8, 0xab, 0x09, 0xfa, 0xd2, + 0x6f, 0x63, 0x49, 0x5e, 0x84, 0x42, 0x78, 0x0c, 0xd2, 0x78, 0x20, 0x3b, 0x8c, 0xbb, 0xf2, 0xd2, + 0x34, 0x72, 0x46, 0x21, 0x5d, 0x35, 0xbf, 0x7f, 0x2e, 0x1d, 0x28, 0xb7, 0xcf, 0xda, 0x6d, 0x4e, + 0x84, 0x68, 0x48, 0xee, 0x7a, 0xb4, 0x3e, 0xa7, 0xc2, 0x27, 0x20, 0x15, 0xb5, 0x36, 0xe3, 0x39, + 0xa3, 0x90, 0xa9, 0x64, 0x9d, 0x95, 0xac, 0x9c, 0xa8, 0x45, 0x35, 0x7d, 0xf5, 0xf3, 0x5e, 0xec, + 0xd3, 0x74, 0x54, 0x34, 0xea, 0x4a, 0x73, 0x72, 0xfc, 0x6e, 0x3a, 0x2a, 0xce, 0xab, 0x7d, 0x98, + 0x8e, 0x8a, 0x47, 0x33, 0xef, 0x17, 0xf3, 0xe9, 0x96, 0xdc, 0xe6, 0xb3, 0xe0, 0x70, 0xe9, 0xa8, + 0x4e, 0x84, 0xcf, 0x3c, 0x41, 0xf2, 0x5f, 0xe3, 0xe0, 0x76, 0x4d, 0xd0, 0x86, 0xc4, 0x5d, 0xd2, + 0x50, 0x7a, 0xf8, 0x08, 0xa4, 0x84, 0x4b, 0x3d, 0xc2, 0x37, 0x8e, 0xa6, 0x78, 0xf0, 0x29, 0xd8, + 0x65, 0xe7, 0x1e, 0xe1, 0x67, 0x38, 0x82, 0xc3, 0xf1, 0xfe, 0x26, 0xdc, 0x09, 0xe9, 0xea, 0x0c, + 0x56, 0xc0, 0xff, 0x5a, 0x98, 0xd8, 0x20, 0xd4, 0x44, 0x88, 0x40, 0x52, 0x04, 0xae, 0xcd, 0xff, + 0x54, 0x92, 0x8a, 0x1e, 0x6c, 0x81, 0xa3, 0xb6, 0xc0, 0x39, 0x65, 0xae, 0x57, 0x8f, 0x78, 0xb0, + 0x0a, 0x6e, 0xa9, 0x8b, 0x15, 0x66, 0x32, 0x97, 0x28, 0x64, 0x2a, 0x0f, 0x6e, 0xa4, 0x1f, 0xde, + 0xbc, 0xa3, 0x23, 0x68, 0x44, 0xc4, 0x53, 0xe6, 0xbd, 0x71, 0x69, 0x7d, 0xa6, 0x3b, 0xc9, 0x04, + 0x37, 0xa0, 0x86, 0xce, 0x5b, 0xc0, 0x5c, 0x8e, 0x6e, 0x96, 0xeb, 0x7b, 0x03, 0xc0, 0x20, 0x73, + 0x4f, 0xfc, 0x63, 0xb2, 0x37, 0xa2, 0x89, 0x6f, 0x19, 0xcd, 0xa2, 0xcb, 0x3b, 0xc0, 0x5a, 0x35, + 0xa2, 0x7d, 0x56, 0xbe, 0xc4, 0x41, 0xa2, 0x26, 0x28, 0x7c, 0x0d, 0x76, 0x16, 0x16, 0x3c, 0xbf, + 0x66, 0x31, 0x97, 0x76, 0xc8, 0x2a, 0x6e, 0xe6, 0xe8, 0x3e, 0x10, 0x83, 0xdd, 0xc5, 0x1d, 0x3b, + 0x5a, 0x2f, 0x5e, 0x20, 0x59, 0x0f, 0xb7, 0x20, 0xcd, 0x5a, 0x50, 0xb0, 0xb7, 0x1c, 0xf7, 0xfd, + 0x3f, 0x38, 0x5c, 0xa4, 0x59, 0xa5, 0xad, 0x68, 0xba, 0x91, 0x95, 0x7c, 0x1b, 0xbc, 0x95, 0xd5, + 0xe7, 0x57, 0x63, 0xdb, 0xb8, 0x1e, 0xdb, 0xc6, 0xaf, 0xb1, 0x6d, 0x7c, 0x9c, 0xd8, 0xb1, 0xeb, + 0x89, 0x1d, 0xfb, 0x31, 0xb1, 0x63, 0xaf, 0xca, 0xd4, 0x95, 0x9d, 0x41, 0xd3, 0x69, 0xb1, 0x3e, + 0x0a, 0x2a, 0x97, 0x3c, 0x22, 0xcf, 0x19, 0xef, 0xa2, 0x75, 0x2f, 0xab, 0xbc, 0xf4, 0x89, 0x68, + 0xa6, 0xc2, 0xff, 0x9a, 0xc7, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x8e, 0xd0, 0xb8, 0xad, 0x58, + 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -715,7 +716,7 @@ func (m *MsgUnstakeSupplier) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Address) i = encodeVarintTx(dAtA, i, uint64(len(m.Address))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 } if len(m.Signer) > 0 { i -= len(m.Signer) @@ -1349,7 +1350,7 @@ func (m *MsgUnstakeSupplier) Unmarshal(dAtA []byte) error { } m.Signer = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) } diff --git a/x/tokenomics/keeper/keeper_settle_pending_claims_test.go b/x/tokenomics/keeper/keeper_settle_pending_claims_test.go index 9375d3870..45f464689 100644 --- a/x/tokenomics/keeper/keeper_settle_pending_claims_test.go +++ b/x/tokenomics/keeper/keeper_settle_pending_claims_test.go @@ -98,9 +98,10 @@ func (s *TestSuite) SetupTest() { supplierStake := types.NewCoin("upokt", math.NewInt(1000000)) supplier := sharedtypes.Supplier{ - Address: supplierAddr, - Stake: &supplierStake, - Services: []*sharedtypes.SupplierServiceConfig{{Service: &service}}, + OwnerAddress: supplierAddr, + Address: supplierAddr, + Stake: &supplierStake, + Services: []*sharedtypes.SupplierServiceConfig{{Service: &service}}, } s.keepers.SetSupplier(s.ctx, supplier) diff --git a/x/tokenomics/keeper/token_logic_modules_test.go b/x/tokenomics/keeper/token_logic_modules_test.go index e76d1246d..8959893fc 100644 --- a/x/tokenomics/keeper/token_logic_modules_test.go +++ b/x/tokenomics/keeper/token_logic_modules_test.go @@ -56,8 +56,9 @@ func TestProcessTokenLogicModules_HandleAppGoingIntoDebt(t *testing.T) { // Add a new supplier supplierStake := cosmostypes.NewCoin("upokt", math.NewInt(1000000)) supplier := sharedtypes.Supplier{ - Address: sample.AccAddress(), - Stake: &supplierStake, + OwnerAddress: sample.AccAddress(), + Address: sample.AccAddress(), + Stake: &supplierStake, } keepers.SetSupplier(ctx, supplier) @@ -115,8 +116,9 @@ func TestProcessTokenLogicModules_ValidAccounting(t *testing.T) { // Add a new supplier. supplierStake := cosmostypes.NewCoin("upokt", math.NewInt(1000000)) supplier := sharedtypes.Supplier{ - Address: sample.AccAddress(), - Stake: &supplierStake, + OwnerAddress: sample.AccAddress(), + Address: sample.AccAddress(), + Stake: &supplierStake, } keepers.SetSupplier(ctx, supplier) @@ -167,10 +169,10 @@ func TestProcessTokenLogicModules_ValidAccounting(t *testing.T) { require.NotNil(t, appModuleEndBalance) require.EqualValues(t, &expectedAppModuleEndBalance, appModuleEndBalance) - // Assert that `supplierAddress` account balance has *increased* by the appropriate amount - supplierEndBalance := getBalance(t, ctx, keepers, supplier.GetAddress()) + // Assert that `supplierOwnerAddress` account balance has *increased* by the appropriate amount + supplierOwnerEndBalance := getBalance(t, ctx, keepers, supplier.GetOwnerAddress()) expectedSupplierBalance := supplierStartBalance.Add(expectedAppBurn) - require.EqualValues(t, &expectedSupplierBalance, supplierEndBalance) + require.EqualValues(t, &expectedSupplierBalance, supplierOwnerEndBalance) // Assert that `supplierAddress` staked balance is *unchanged* supplier, supplierIsFound := keepers.GetSupplier(ctx, supplier.GetAddress()) @@ -224,13 +226,15 @@ func TestProcessTokenLogicModules_AppStakeTooLow(t *testing.T) { // Add a new supplier. supplierStake := cosmostypes.NewCoin("upokt", math.NewInt(1000000)) supplier := sharedtypes.Supplier{ - Address: sample.AccAddress(), - Stake: &supplierStake, + OwnerAddress: sample.AccAddress(), + Address: sample.AccAddress(), + Stake: &supplierStake, } keepers.SetSupplier(ctx, supplier) - // Query supplier balance prior to the accounting. - supplierStartBalance := getBalance(t, ctx, keepers, supplier.GetAddress()) + // Query supplier owner balance prior to the accounting. + supplierOwnerStartBalance := getBalance(t, ctx, keepers, supplier.GetOwnerAddress()) + // Query supplier module balance prior to the accounting. supplierModuleStartBalance := getBalance(t, ctx, keepers, supplierModuleAddress) @@ -271,12 +275,12 @@ func TestProcessTokenLogicModules_AppStakeTooLow(t *testing.T) { require.NotNil(t, appModuleEndBalance) require.EqualValues(t, &expectedAppModuleEndBalance, appModuleEndBalance) - // Assert that `supplierAddress` account balance has *increased* by the appropriate amount - supplierEndBalance := getBalance(t, ctx, keepers, supplier.GetAddress()) - require.NotNil(t, supplierEndBalance) + // Assert that `supplierOwnerAddress` account balance has *increased* by the appropriate amount + supplierOwnerEndBalance := getBalance(t, ctx, keepers, supplier.GetOwnerAddress()) + require.NotNil(t, supplierOwnerEndBalance) - expectedSupplierBalance := supplierStartBalance.Add(expectedAppBurn) - require.EqualValues(t, &expectedSupplierBalance, supplierEndBalance) + expectedSupplierBalance := supplierOwnerStartBalance.Add(expectedAppBurn) + require.EqualValues(t, &expectedSupplierBalance, supplierOwnerEndBalance) // Assert that `supplierAddress` staked balance is *unchanged* supplier, supplierIsFound := keepers.GetSupplier(ctx, supplier.GetAddress())