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

Add tests for authorizers #846

Merged
merged 17 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
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
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.8.18-0.20230823135357-61db9486f4c0
github.com/0chain/gosdk v1.10.1-0.20231027034008-e99291168a4f
github.com/go-resty/resty/v2 v2.7.0
github.com/herumi/bls-go-binary v1.31.0
github.com/shopspring/decimal v1.3.1
Expand All @@ -23,12 +23,13 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/lithammer/shortuuid/v3 v3.0.7 // indirect
github.com/remeh/sizedwaitgroup v1.0.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
)

require github.com/aws/aws-sdk-go v1.44.289
require github.com/aws/aws-sdk-go v1.44.331

require (
github.com/0chain/common v0.0.6-0.20230127095721-8df4d1d72565 // indirect
Expand Down Expand Up @@ -85,7 +86,7 @@ require (
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.dedis.ch/fixbuf v1.0.3 // indirect
go.dedis.ch/kyber/v3 v3.1.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
Expand Down
17 changes: 10 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/0chain/common v0.0.6-0.20230127095721-8df4d1d72565 h1:z+DtCR8mBsjPnEs
github.com/0chain/common v0.0.6-0.20230127095721-8df4d1d72565/go.mod h1:UyDC8Qyl5z9lGkCnf9RHJPMektnFX8XtCJZHXCCVj8E=
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
github.com/0chain/gosdk v1.8.18-0.20230823135357-61db9486f4c0 h1:XhLlPJKQxohZAS1+H2MHxy/e5I9Pw+Iyi+KaC5NHPl8=
github.com/0chain/gosdk v1.8.18-0.20230823135357-61db9486f4c0/go.mod h1:3NKNYzmnMIYqZwwwOgZwMmTW1DT1ZUAmKyVPmYQOiT4=
github.com/0chain/gosdk v1.10.1-0.20231027034008-e99291168a4f h1:Eb2rYn3dqhrv0Kuyi9R0Pmi2FuFEVZoYEufW9XXFLkE=
github.com/0chain/gosdk v1.10.1-0.20231027034008-e99291168a4f/go.mod h1:d3YLgnSKvEtZ6I9taIQotb6xcMvUKvd01JnkXS+O1jk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Luzifer/go-openssl/v3 v3.1.0 h1:QqKqo6kYXGGUsvtUoCpRZm8lHw+jDfhbzr36gVj+/gw=
Expand All @@ -59,8 +59,8 @@ github.com/antchfx/xmlquery v1.3.17/go.mod h1:Afkq4JIeXut75taLSuI31ISJ/zeq+3jG7T
github.com/antchfx/xpath v1.2.3/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
github.com/antchfx/xpath v1.2.4 h1:dW1HB/JxKvGtJ9WyVGJ0sIoEcqftV3SqIstujI+B9XY=
github.com/antchfx/xpath v1.2.4/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
github.com/aws/aws-sdk-go v1.44.289 h1:5CVEjiHFvdiVlKPBzv0rjG4zH/21W/onT18R5AH/qx0=
github.com/aws/aws-sdk-go v1.44.289/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.44.331 h1:hEwdOTv6973uegCUY2EY8jyyq0OUg9INc0HOzcu2bjw=
github.com/aws/aws-sdk-go v1.44.331/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
Expand Down Expand Up @@ -172,8 +172,8 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -223,7 +223,7 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/herumi/bls-go-binary v1.31.0 h1:L1goQ2tMtGgpXCg5AwHAdJQpLs/pfnWWEc3Wog6OhmI=
github.com/herumi/bls-go-binary v1.31.0/go.mod h1:O4Vp1AfR4raRGwFeQpr9X/PQtncEicMoOe6BQt1oX0Y=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c h1:DZfsyhDK1hnSS5lH8l+JggqzEleHteTYfutAiVlSUM8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down Expand Up @@ -295,6 +295,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA=
github.com/remeh/sizedwaitgroup v1.0.0 h1:VNGGFwNo/R5+MJBf6yrsr110p0m4/OX4S3DCy7Kyl5E=
github.com/remeh/sizedwaitgroup v1.0.0/go.mod h1:3j2R4OIe/SeS6YDhICBy22RWjJC5eNCJ1V+9+NVNYlo=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down Expand Up @@ -472,8 +474,9 @@ golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
143 changes: 143 additions & 0 deletions tests/cli_tests/zwalletcli_zcnbridge_add_and_rm_authorizer_test.go
Copy link
Collaborator

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

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)
}
}
Loading
Loading