From 7161be36484ceb8b627046b53857422c77f005b0 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Thu, 25 Apr 2024 14:52:37 -0700 Subject: [PATCH 1/3] Add supplier staking E2E tests --- Makefile | 4 ++++ e2e/tests/init_test.go | 22 ++++++++++++++++++++-- e2e/tests/stake_supplier.feature | 28 ++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 e2e/tests/stake_supplier.feature diff --git a/Makefile b/Makefile index 1e501f2b9..ad52ee2b9 100644 --- a/Makefile +++ b/Makefile @@ -322,6 +322,10 @@ test_e2e: test_e2e_env ## Run all E2E tests test_e2e_app: go test -v ./e2e/tests/... -tags=e2e,test --features-path=stake_app.feature +.PHONY: test_e2e_supplier +test_e2e_supplier: + go test -v ./e2e/tests/... -tags=e2e,test --features-path=stake_supplier.feature + .PHONY: test_e2e_gateway test_e2e_gateway: go test -v ./e2e/tests/... -tags=e2e,test --features-path=stake_gateway.feature diff --git a/e2e/tests/init_test.go b/e2e/tests/init_test.go index 2f5e7d68e..500d046c8 100644 --- a/e2e/tests/init_test.go +++ b/e2e/tests/init_test.go @@ -118,6 +118,7 @@ func (s *suite) TheUserRunsTheCommand(cmd string) { } func (s *suite) TheUserShouldBeAbleToSeeStandardOutputContaining(arg1 string) { + fmt.Println(s.pocketd.result.Stdout, "~~~", arg1) require.Contains(s, s.pocketd.result.Stdout, arg1) } @@ -219,14 +220,31 @@ func (s *suite) TheUserStakesAWithUpoktFromTheAccount(actorType string, amount i func (s *suite) TheUserStakesAWithUpoktForServiceFromTheAccount(actorType string, amount int64, serviceId, accName string) { // Create a temporary config file - configPathPattern := fmt.Sprintf("%s_stake_config_*.yaml", accName) + configPathPattern := fmt.Sprintf("%s_stake_config.yaml", accName) configFile, err := os.CreateTemp("", configPathPattern) require.NoError(s, err, "error creating config file in %q", path.Join(os.TempDir(), configPathPattern)) - configContent := fmt.Sprintf("stake_amount: %d upokt\nservice_ids:\n - %s", amount, serviceId) + // Prepare the config content based on the actor type + var configContent string + switch actorType { + case "application": + configContent = fmt.Sprintf("stake_amount: %d upokt\nservice_ids:\n - %s", amount, serviceId) + case "supplier": + configContent = fmt.Sprintf(`stake_amount: %dupokt +services: + - service_id: %s + endpoints: + - publicly_exposed_url: http://relayminer:8545 + rpc_type: json_rpc`, amount, serviceId) + default: + s.Fatalf("unknown actor type %s", actorType) + } + + // Write the config content to the file _, err = configFile.Write([]byte(configContent)) require.NoError(s, err, "error writing config file %q", configFile.Name()) + // Prepare the command arguments args := []string{ "tx", actorType, diff --git a/e2e/tests/stake_supplier.feature b/e2e/tests/stake_supplier.feature new file mode 100644 index 000000000..fc7776c64 --- /dev/null +++ b/e2e/tests/stake_supplier.feature @@ -0,0 +1,28 @@ +Feature: Stake Supplier Namespace + + Scenario: User can stake a Supplier + Given the user has the pocketd binary installed + And the "supplier" for account "supplier2" is not staked + # Stake with 1 uPOKT more than the current stake used in genesis to make + # the transaction succeed. + And the account "supplier2" has a balance greater than "1000070" uPOKT + When the user stakes a "supplier" with "1000070" uPOKT for "anvil" service from the account "supplier2" + Then the user should be able to see standard output containing "txhash:" + And the user should be able to see standard output containing "code: 0" + And the pocketd binary should exit without error + # TODO_TECHDEBT(@Olshansk, @red-0ne): Replace these time-based waits with event listening waits + And the user should wait for "5" seconds + And the "supplier" for account "supplier2" is staked with "1000070" uPOKT + And the account balance of "supplier2" should be "1000070" uPOKT "less" than before + + Scenario: User can unstake a Supplier + Given the user has the pocketd binary installed + And the "supplier" for account "supplier2" is staked with "1000070" uPOKT + And an account exists for "supplier2" + When the user unstakes a "supplier" from the account "supplier2" + Then the user should be able to see standard output containing "txhash:" + And the user should be able to see standard output containing "code: 0" + And the pocketd binary should exit without error + And the user should wait for "5" seconds + And the "supplier" for account "supplier2" is not staked + And the account balance of "supplier2" should be "1000070" uPOKT "more" than before \ No newline at end of file From 357ede53842a7af9f0866848d716a10e60d44fa5 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Thu, 25 Apr 2024 15:01:01 -0700 Subject: [PATCH 2/3] Empty commit From 6e3c7a09147589d13cbcf4a93dc3f45c071544fc Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sat, 27 Apr 2024 13:14:17 -0700 Subject: [PATCH 3/3] Fixed yaml normalization --- e2e/tests/init_test.go | 44 ++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/e2e/tests/init_test.go b/e2e/tests/init_test.go index 500d046c8..ea859cb41 100644 --- a/e2e/tests/init_test.go +++ b/e2e/tests/init_test.go @@ -24,6 +24,7 @@ import ( "github.com/pokt-network/poktroll/app" "github.com/pokt-network/poktroll/testutil/testclient" + "github.com/pokt-network/poktroll/testutil/yaml" apptypes "github.com/pokt-network/poktroll/x/application/types" prooftypes "github.com/pokt-network/poktroll/x/proof/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" @@ -118,7 +119,6 @@ func (s *suite) TheUserRunsTheCommand(cmd string) { } func (s *suite) TheUserShouldBeAbleToSeeStandardOutputContaining(arg1 string) { - fmt.Println(s.pocketd.result.Stdout, "~~~", arg1) require.Contains(s, s.pocketd.result.Stdout, arg1) } @@ -224,23 +224,8 @@ func (s *suite) TheUserStakesAWithUpoktForServiceFromTheAccount(actorType string configFile, err := os.CreateTemp("", configPathPattern) require.NoError(s, err, "error creating config file in %q", path.Join(os.TempDir(), configPathPattern)) - // Prepare the config content based on the actor type - var configContent string - switch actorType { - case "application": - configContent = fmt.Sprintf("stake_amount: %d upokt\nservice_ids:\n - %s", amount, serviceId) - case "supplier": - configContent = fmt.Sprintf(`stake_amount: %dupokt -services: - - service_id: %s - endpoints: - - publicly_exposed_url: http://relayminer:8545 - rpc_type: json_rpc`, amount, serviceId) - default: - s.Fatalf("unknown actor type %s", actorType) - } - // Write the config content to the file + configContent := s.getConfigFileContent(amount, actorType, serviceId) _, err = configFile.Write([]byte(configContent)) require.NoError(s, err, "error writing config file %q", configFile.Name()) @@ -266,6 +251,31 @@ services: s.pocketd.result = res } +func (s *suite) getConfigFileContent(amount int64, actorType, serviceId string) string { + var configContent string + switch actorType { + case "application": + configContent = fmt.Sprintf(` + stake_amount: %dupokt + service_ids: + - %s`, + amount, serviceId) + case "supplier": + configContent = fmt.Sprintf(` + stake_amount: %dupokt + services: + - service_id: %s + endpoints: + - publicly_exposed_url: http://relayminer:8545 + rpc_type: json_rpc`, + amount, serviceId) + default: + s.Fatalf("unknown actor type %s", actorType) + } + fmt.Println(yaml.NormalizeYAMLIndentation(configContent)) + return yaml.NormalizeYAMLIndentation(configContent) +} + func (s *suite) TheUserUnstakesAFromTheAccount(actorType string, accName string) { args := []string{ "tx",