-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add tests for authorizers #846
Merged
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
061ca8d
Add authorizers DEX sc add and remove tests
peterlimg 83c32f4
Add authorizers tests
peterlimg e1b7662
Add zcn burn and wzcn mint test
peterlimg b6597b2
Move auth replace mint/burn to a separate file
peterlimg 5f5f60b
Add TODO
peterlimg 37a5a33
Merge branch 'sprint-1.11' into feat/authorizer-tests
Kishan-Dhakan af1baa7
update gosdk
Kishan-Dhakan d028a85
add config path
Kishan-Dhakan b135c4a
add config path, enable retries
Kishan-Dhakan 400ecf4
Merge branch 'sprint-1.11' into feat/authorizer-tests
stewartie4 49d496d
Merge branch 'sprint-1.11' into feat/authorizer-tests
Kishan-Dhakan f70ac58
Adjust comments
peterlimg 7a47c04
Merge branch 'sprint-1.11' into feat/authorizer-tests
YarikRevich 17ae98a
Merge branch 'sprint-1.11' into feat/authorizer-tests
YarikRevich 7ab97af
update to sprint gosdk
Kishan-Dhakan 54d14b5
Merge branch 'sprint-1.11' into feat/authorizer-tests
Kishan-Dhakan 7e130eb
Fix --path for bridge-auth-delete
peterlimg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
tests/cli_tests/zwalletcli_zcnbridge_add_and_rm_authorizer_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package cli_tests | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/0chain/system_test/internal/api/util/test" | ||
cliutils "github.com/0chain/system_test/internal/cli/util" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestZCNBridgeAuthorizerRegisterAndDelete(testSetup *testing.T) { // nolint:gocyclo // team preference is to have codes all within test. | ||
t := test.NewSystemTest(testSetup) | ||
output, err := createWallet(t, configPath) | ||
require.NoError(t, err, "Unexpected create wallet failure", strings.Join(output, "\n")) | ||
|
||
t.RunSequentially("Register authorizer to DEX smartcontract", func(t *test.SystemTest) { | ||
output, err = scRegisterAuthorizer(t, "0xEa36456C79caD6Dd941Fe552285594C7217Fe258", true) | ||
require.NoError(t, err, "error trying to register authorizer to DEX sc: %s", strings.Join(output, "\n")) | ||
t.Log("register authorizer DEX SC successfully") | ||
}) | ||
|
||
t.RunSequentially("Remove authorizer from DEX smartcontract", func(t *test.SystemTest) { | ||
output, err = scRemoveAuthorizer(t, "0xEa36456C79caD6Dd941Fe552285594C7217Fe258", true) | ||
require.NoError(t, err, strings.Join(output, "\n")) | ||
t.Log("remove authorizer DEX SC successfully") | ||
}) | ||
} | ||
|
||
func TestZCNAuthorizerRegisterAndDelete(testSetup *testing.T) { | ||
t := test.NewSystemTest(testSetup) | ||
output, err := createWallet(t, configPath) | ||
require.NoError(t, err, "Unexpected create wallet failure", strings.Join(output, "\n")) | ||
|
||
w, err := getWallet(t, configPath) | ||
require.NoError(t, err) | ||
|
||
var ( | ||
publicKey = w.ClientPublicKey | ||
clientID = w.ClientID | ||
authURL = "http://systemtest.network/authorizer01" | ||
) | ||
// faucet pour to sc owner wallet | ||
output, err = executeFaucetWithTokensForWallet(t, "wallets/sc_owner", configPath, defaultInitFaucetTokens) | ||
require.NoError(t, err, "Unexpected faucet execution failure", strings.Join(output, "\n")) | ||
|
||
t.RunSequentially("Register authorizer to zcnsc smartcontract", func(t *test.SystemTest) { | ||
output, err := registerAuthorizer(t, clientID, publicKey, authURL, true) | ||
require.NoError(t, err, "error trying to register authorizer to zcnsc: %s", strings.Join(output, "\n")) | ||
t.Log("register authorizer zcnsc successfully") | ||
}) | ||
|
||
t.RunSequentially("Remove authorizer from zcnsc smartcontract", func(t *test.SystemTest) { | ||
output, err := removeAuthorizer(t, clientID, true) | ||
require.NoError(t, err, strings.Join(output, "\n")) | ||
t.Log("remove authorizer zcnsc successfully") | ||
}) | ||
} | ||
|
||
func scRegisterAuthorizer(t *test.SystemTest, authAddress string, retry bool) ([]string, error) { | ||
t.Logf("Register authorizer to SC...") | ||
cmd := fmt.Sprintf( | ||
"./zwallet auth-sc-register "+ | ||
"--ethereum_address=%s "+ | ||
"--silent "+ | ||
"--path %s "+ | ||
"--configDir ./config "+ | ||
"--wallet %s", | ||
authAddress, | ||
configDir, | ||
escapedTestName(t)+"_wallet.json", | ||
) | ||
|
||
if retry { | ||
return cliutils.RunCommand(t, cmd, 3, time.Second*2) | ||
} else { | ||
return cliutils.RunCommandWithoutRetry(cmd) | ||
} | ||
} | ||
|
||
func scRemoveAuthorizer(t *test.SystemTest, authAddress string, retry bool) ([]string, error) { | ||
t.Logf("Remove authorizer to SC ...") | ||
cmd := fmt.Sprintf( | ||
"./zwallet auth-sc-delete --ethereum_address=%s "+ | ||
"--silent "+ | ||
"--path %s "+ | ||
"--configDir ./config "+ | ||
"--wallet %s", | ||
authAddress, | ||
configDir, | ||
escapedTestName(t)+"_wallet.json", | ||
) | ||
|
||
if retry { | ||
return cliutils.RunCommand(t, cmd, 3, time.Second*2) | ||
} else { | ||
return cliutils.RunCommandWithoutRetry(cmd) | ||
} | ||
} | ||
|
||
func registerAuthorizer(t *test.SystemTest, clientID, publicKey, authURL string, retry bool) ([]string, error) { | ||
t.Log("Register authorizer to zcnsc ...") | ||
|
||
cmd := fmt.Sprintf(` | ||
./zwallet auth-register --silent | ||
--configDir ./config | ||
--path %s | ||
--wallet wallets/sc_owner_wallet.json | ||
--client_id %s | ||
--client_key %s | ||
--url %s | ||
--min_stake 1 | ||
--max_stake 10 | ||
--service_charge 0.1 | ||
--num_delegates 5`, | ||
configDir, clientID, publicKey, authURL) | ||
|
||
if retry { | ||
return cliutils.RunCommand(t, cmd, 3, time.Second*2) | ||
} else { | ||
return cliutils.RunCommandWithoutRetry(cmd) | ||
} | ||
} | ||
|
||
func removeAuthorizer(t *test.SystemTest, clientID string, retry bool) ([]string, error) { | ||
t.Log("Remove authorizer from zcnsc ...") | ||
|
||
cmd := fmt.Sprintf(` | ||
./zwallet bridge-auth-delete --silent | ||
--configDir ./config | ||
--path %s | ||
--wallet wallets/sc_owner_wallet.json | ||
--id %s`, | ||
configDir, clientID) | ||
|
||
if retry { | ||
return cliutils.RunCommand(t, cmd, 3, time.Second*2) | ||
} else { | ||
return cliutils.RunCommandWithoutRetry(cmd) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can associate these test cases into one file regarding authorizer tests