Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Supplier] Refactor/non custodial staking tests #718

Merged
merged 53 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
a18ba42
feat: Implement non-custodial staking
red-0ne Jul 30, 2024
676c2c4
chore: Address review change requests
red-0ne Aug 1, 2024
14ea326
Merge remote-tracking branch 'origin/main' into refactor/non-custodia…
red-0ne Aug 1, 2024
bae1f00
refactor: unit/integration tests
red-0ne Aug 2, 2024
b44e07b
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 2, 2024
5f5e98b
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 2, 2024
473e042
fix: Remove tabs and non-printable chars
red-0ne Aug 2, 2024
3d01f53
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 2, 2024
2d064fd
Merge branch 'feat/non-custodial-staking' into refactor/non-custodial…
red-0ne Aug 2, 2024
0699a35
fix: Remove shadowed variable
red-0ne Aug 2, 2024
85e6b81
Merge remote-tracking branch 'origin/main' into refactor/non-custodia…
red-0ne Aug 2, 2024
bb84ab1
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 2, 2024
498fc26
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 2, 2024
853724a
fix: All tests working
red-0ne Aug 3, 2024
6d7151e
fix: Revert merge changes
red-0ne Aug 3, 2024
20b26e7
chore: Remove imoprt newline
red-0ne Aug 3, 2024
b33a013
fix: Add missing sender address
red-0ne Aug 3, 2024
b02af2f
fix: Use higher context err variable
red-0ne Aug 3, 2024
7b3555a
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 3, 2024
604224d
fix: Enfore sender to be owner or operator
red-0ne Aug 3, 2024
540f5db
Merge branch 'feat/non-custodial-staking' into refactor/non-custodial…
red-0ne Aug 3, 2024
ac07b43
fix: Remove err shadow declaration
red-0ne Aug 3, 2024
79e4c39
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 5, 2024
473e047
fix: Err var shadowing
red-0ne Aug 6, 2024
088e675
chore: Log default operator address fallback
red-0ne Aug 6, 2024
428104b
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 7, 2024
ef62442
Merge branch 'feat/non-custodial-staking' into refactor/non-custodial…
red-0ne Aug 7, 2024
365ee96
fix: Add missing ctx argument
red-0ne Aug 7, 2024
d096d02
fix: Add polylog as side effect
red-0ne Aug 7, 2024
20e8ed5
fix: Address review changes, mimic Morse behavior
red-0ne Aug 8, 2024
b543120
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 8, 2024
fdfd9b9
fix: Duplicate supplierKeeper declaration
red-0ne Aug 8, 2024
4843c21
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 8, 2024
095571a
fix: Reward the owner instead of the operator
red-0ne Aug 8, 2024
611f583
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 8, 2024
3a7c0ba
fix: Update tests
red-0ne Aug 9, 2024
e34634b
chore: Add test external signer test case
red-0ne Aug 9, 2024
910c85b
fix: Allow owner to change its aaddress
red-0ne Aug 9, 2024
e092a4e
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 9, 2024
b3ac63c
fix: Wrong word added
red-0ne Aug 9, 2024
1f26789
fix: Stake auth contidional
red-0ne Aug 9, 2024
0a43775
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 9, 2024
85d84ec
fix: Missing owner address in test
red-0ne Aug 9, 2024
391b6db
chore: Address review change requests
red-0ne Aug 9, 2024
98b0446
Merge remote-tracking branch 'origin/main' into feat/non-custodial-st…
red-0ne Aug 9, 2024
7b78f49
Merge branch 'feat/non-custodial-staking' into refactor/non-custodial…
red-0ne Aug 9, 2024
8060f46
chore: Address review change requests
red-0ne Aug 13, 2024
2deda3b
test: Add test assertion
red-0ne Aug 13, 2024
b887a0c
fix: Error sequence
red-0ne Aug 13, 2024
8121719
chore: Remove unused method
red-0ne Aug 13, 2024
11ef9bb
Merge remote-tracking branch 'origin/feat/non-custodial-staking' into…
red-0ne Aug 13, 2024
1bd3182
fix: Rename Errors in tests
red-0ne Aug 13, 2024
e52e1d9
Merge remote-tracking branch 'origin/main' into refactor/non-custodia…
red-0ne Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 "| |"
Expand All @@ -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 "+-----------------------------------------------------------------------------------------------+"
Expand Down
8 changes: 4 additions & 4 deletions api/poktroll/supplier/tx.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ genesis:
denom: upokt
supplier:
supplierList:
- address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj
- owner_address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj
address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj
services:
- service:
id: anvil
Expand Down
50 changes: 38 additions & 12 deletions e2e/tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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":
Expand All @@ -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)
}
Expand All @@ -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...)
Expand Down
2 changes: 1 addition & 1 deletion proto/poktroll/supplier/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
5 changes: 3 additions & 2 deletions testutil/integration/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 13 additions & 3 deletions testutil/keeper/supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions testutil/keeper/tokenomics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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"},
Expand Down
Loading
Loading