mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 03:41:34 +00:00
Merge pull request #3332 from nspcc-dev/fix-nep17-test
cli: fix race in TestNEP17Balance
This commit is contained in:
commit
8d67f17943
23 changed files with 240 additions and 122 deletions
|
@ -16,7 +16,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
},
|
||||
{
|
||||
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
|
||||
|
@ -41,7 +41,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
}
|
||||
],
|
||||
"scrypt": {
|
||||
|
@ -52,4 +52,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
},
|
||||
{
|
||||
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
|
||||
|
@ -41,7 +41,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
},
|
||||
{
|
||||
"address": "NfgHwwTi3wHAS8aFAN243C5vGbkYDpqLHP",
|
||||
|
@ -58,7 +58,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
}
|
||||
],
|
||||
"scrypt": {
|
||||
|
@ -69,4 +69,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
},
|
||||
{
|
||||
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
|
||||
|
@ -41,7 +41,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
}
|
||||
],
|
||||
"scrypt": {
|
||||
|
@ -52,4 +52,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
},
|
||||
{
|
||||
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
|
||||
|
@ -41,7 +41,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
}
|
||||
],
|
||||
"scrypt": {
|
||||
|
@ -52,4 +52,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
},
|
||||
{
|
||||
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
|
||||
|
@ -41,7 +41,7 @@
|
|||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isdefault": false
|
||||
"isDefault": false
|
||||
}
|
||||
],
|
||||
"scrypt": {
|
||||
|
@ -52,4 +52,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,19 +19,34 @@ import (
|
|||
|
||||
func TestNEP17Balance(t *testing.T) {
|
||||
e := testcli.NewExecutor(t, true)
|
||||
|
||||
args := []string{
|
||||
"neo-go", "wallet", "nep17", "multitransfer",
|
||||
"--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
|
||||
"--wallet", testcli.ValidatorWallet,
|
||||
"--from", testcli.ValidatorAddr,
|
||||
"GAS:" + testcli.TestWalletMultiAccount1 + ":1",
|
||||
"NEO:" + testcli.TestWalletMultiAccount1 + ":10",
|
||||
"GAS:" + testcli.TestWalletMultiAccount3 + ":3",
|
||||
"--force",
|
||||
}
|
||||
e.In.WriteString("one\r")
|
||||
e.Run(t, args...)
|
||||
e.CheckTxPersisted(t)
|
||||
|
||||
cmdbalance := []string{"neo-go", "wallet", "nep17", "balance"}
|
||||
cmdbase := append(cmdbalance,
|
||||
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
||||
"--wallet", testcli.ValidatorWallet,
|
||||
"--wallet", testcli.TestWalletMultiPath,
|
||||
)
|
||||
cmd := append(cmdbase, "--address", testcli.ValidatorAddr)
|
||||
cmd := append(cmdbase, "--address", testcli.TestWalletMultiAccount1)
|
||||
t.Run("excessive parameters", func(t *testing.T) {
|
||||
e.RunWithError(t, append(cmd, "--token", "NEO", "gas")...)
|
||||
})
|
||||
t.Run("NEO", func(t *testing.T) {
|
||||
b, index := e.Chain.GetGoverningTokenBalance(testcli.ValidatorHash)
|
||||
b, index := e.Chain.GetGoverningTokenBalance(testcli.TestWalletMultiAccount1Hash)
|
||||
checkResult := func(t *testing.T) {
|
||||
e.CheckNextLine(t, "^\\s*Account\\s+"+testcli.ValidatorAddr)
|
||||
e.CheckNextLine(t, "^\\s*Account\\s+"+testcli.TestWalletMultiAccount1)
|
||||
e.CheckNextLine(t, "^\\s*NEO:\\s+NeoToken \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)")
|
||||
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$")
|
||||
e.CheckNextLine(t, "^\\s*Updated\\s*:\\s*"+strconv.FormatUint(uint64(index), 10))
|
||||
|
@ -48,65 +63,53 @@ func TestNEP17Balance(t *testing.T) {
|
|||
})
|
||||
t.Run("GAS", func(t *testing.T) {
|
||||
e.Run(t, append(cmd, "--token", "GAS")...)
|
||||
e.CheckNextLine(t, "^\\s*Account\\s+"+testcli.ValidatorAddr)
|
||||
e.CheckNextLine(t, "^\\s*Account\\s+"+testcli.TestWalletMultiAccount1)
|
||||
e.CheckNextLine(t, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)")
|
||||
b := e.Chain.GetUtilityTokenBalance(testcli.ValidatorHash)
|
||||
b := e.Chain.GetUtilityTokenBalance(testcli.TestWalletMultiAccount1Hash)
|
||||
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(b.Int64()).String()+"$")
|
||||
})
|
||||
t.Run("zero balance of known token", func(t *testing.T) {
|
||||
e.Run(t, append(cmdbase, []string{"--token", "NEO"}...)...)
|
||||
addr1, err := address.StringToUint160("Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn")
|
||||
require.NoError(t, err)
|
||||
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr1))
|
||||
e.Run(t, append(cmdbase, []string{"--token", "NEO", "--address", testcli.TestWalletMultiAccount2}...)...)
|
||||
e.CheckNextLine(t, "^Account "+testcli.TestWalletMultiAccount2)
|
||||
e.CheckNextLine(t, "^\\s*NEO:\\s+NeoToken \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)")
|
||||
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(0).String()+"$")
|
||||
e.CheckNextLine(t, "^\\s*Updated:")
|
||||
e.CheckNextLine(t, "^\\s*$")
|
||||
e.CheckEOF(t)
|
||||
})
|
||||
t.Run("all accounts", func(t *testing.T) {
|
||||
e.Run(t, cmdbase...)
|
||||
addr1, err := address.StringToUint160("Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn")
|
||||
require.NoError(t, err)
|
||||
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr1))
|
||||
e.CheckNextLine(t, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)")
|
||||
balance := e.Chain.GetUtilityTokenBalance(addr1)
|
||||
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(balance.Int64()).String()+"$")
|
||||
e.CheckNextLine(t, "^\\s*Updated:")
|
||||
e.CheckNextLine(t, "^\\s*$")
|
||||
|
||||
addr2, err := address.StringToUint160("NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq")
|
||||
require.NoError(t, err)
|
||||
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr2))
|
||||
e.CheckNextLine(t, "^\\s*$")
|
||||
|
||||
addr3, err := address.StringToUint160("NfgHwwTi3wHAS8aFAN243C5vGbkYDpqLHP")
|
||||
require.NoError(t, err)
|
||||
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr3))
|
||||
e.CheckNextLine(t, "^Account "+testcli.TestWalletMultiAccount1)
|
||||
// The order of assets is undefined.
|
||||
for i := 0; i < 2; i++ {
|
||||
line := e.GetNextLine(t)
|
||||
if strings.Contains(line, "GAS") {
|
||||
e.CheckLine(t, line, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)")
|
||||
balance = e.Chain.GetUtilityTokenBalance(addr3)
|
||||
balance := e.Chain.GetUtilityTokenBalance(testcli.TestWalletMultiAccount1Hash)
|
||||
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(balance.Int64()).String()+"$")
|
||||
e.CheckNextLine(t, "^\\s*Updated:")
|
||||
} else {
|
||||
balance, index := e.Chain.GetGoverningTokenBalance(testcli.ValidatorHash)
|
||||
balance, index := e.Chain.GetGoverningTokenBalance(testcli.TestWalletMultiAccount1Hash)
|
||||
e.CheckLine(t, line, "^\\s*NEO:\\s+NeoToken \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)")
|
||||
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+balance.String()+"$")
|
||||
e.CheckNextLine(t, "^\\s*Updated\\s*:\\s*"+strconv.FormatUint(uint64(index), 10))
|
||||
}
|
||||
}
|
||||
|
||||
e.CheckNextLine(t, "^\\s*$")
|
||||
addr4, err := address.StringToUint160("NiFxRcC5Anz9pmqQyMHh5vamBUZDbRRRzA") // deployed verify.go contract
|
||||
require.NoError(t, err)
|
||||
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr4))
|
||||
|
||||
e.CheckNextLine(t, "^Account "+testcli.TestWalletMultiAccount2)
|
||||
e.CheckNextLine(t, "^\\s*$")
|
||||
|
||||
e.CheckNextLine(t, "^Account "+testcli.TestWalletMultiAccount3)
|
||||
e.CheckNextLine(t, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)")
|
||||
balance := e.Chain.GetUtilityTokenBalance(testcli.TestWalletMultiAccount3Hash)
|
||||
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(balance.Int64()).String()+"$")
|
||||
e.CheckNextLine(t, "^\\s*Updated:")
|
||||
e.CheckEOF(t)
|
||||
})
|
||||
t.Run("Bad token", func(t *testing.T) {
|
||||
e.Run(t, append(cmd, "--token", "kek")...)
|
||||
e.CheckNextLine(t, "^\\s*Account\\s+"+testcli.ValidatorAddr)
|
||||
e.CheckNextLine(t, "^\\s*Account\\s+"+testcli.TestWalletMultiAccount1)
|
||||
e.CheckNextLine(t, `^\s*Can't find data for "kek" token\s*`)
|
||||
e.CheckEOF(t)
|
||||
})
|
||||
|
|
2
cli/testdata/testwallet.json
vendored
2
cli/testdata/testwallet.json
vendored
|
@ -27,4 +27,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
64
cli/testdata/testwallet_multi.json
vendored
Normal file
64
cli/testdata/testwallet_multi.json
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
"version": "1.0",
|
||||
"accounts": [
|
||||
{
|
||||
"address": "NgHcPxgEKZQV4QBedzyASJrgiANhJqBVLw",
|
||||
"key": "6PYTbVq2P3AJQwWU5SFMKLjHYco7QABtNRo4ZvLvXhyaYjwMcuZm6xKokT",
|
||||
"label": "one",
|
||||
"contract": {
|
||||
"script": "DCECnmSGVirDOqMr57EHaYz0YMTjaHQtO9FQYu8DMTCDw6VBVuezJw==",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "parameter0",
|
||||
"type": "Signature"
|
||||
}
|
||||
],
|
||||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isDefault": false
|
||||
},
|
||||
{
|
||||
"address": "NLvHRfKAifjio2z9HiwLo9ZnpRPHUbAHgH",
|
||||
"key": "6PYUjQ8TgR3cduEpG5niUNuPEWi3tYiQsnC4Jha9nGAJ6tAQGUmcrZXsLF",
|
||||
"label": "two",
|
||||
"contract": {
|
||||
"script": "DCECgk91c1ABAX3A1uJNnxhGlp7NwUJScwJzJhrsYrXIbgNBVuezJw==",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "parameter0",
|
||||
"type": "Signature"
|
||||
}
|
||||
],
|
||||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isDefault": false
|
||||
},
|
||||
{
|
||||
"address": "NcDfG8foJx79XSihcDDrx1df7cHAoJBfXj",
|
||||
"key": "6PYRkUQKWFrTovHyeQZ7X4nWoDXKohtFRKW51LiCz317pwCjmB1cVwpcxz",
|
||||
"label": "three",
|
||||
"contract": {
|
||||
"script": "DCEC9v0ZqBg8f4jJX9WR891M0bazf0FYTNu7MEgpSHrb9CVBVuezJw==",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "parameter0",
|
||||
"type": "Signature"
|
||||
}
|
||||
],
|
||||
"deployed": false
|
||||
},
|
||||
"lock": false,
|
||||
"isDefault": false
|
||||
}
|
||||
],
|
||||
"scrypt": {
|
||||
"n": 2,
|
||||
"r": 1,
|
||||
"p": 1
|
||||
},
|
||||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
3
cli/testdata/wallet1_solo.json
vendored
3
cli/testdata/wallet1_solo.json
vendored
|
@ -65,6 +65,7 @@
|
|||
"key": "6PYSATFztBa3CHjSR6sLAKungUEAbQUCVE16KzmaQQ38gLeYGZ9Knd5mGv",
|
||||
"label": "verify",
|
||||
"contract": {
|
||||
"script": "VwEAEUBXAANA",
|
||||
"parameters": [],
|
||||
"deployed": true
|
||||
},
|
||||
|
@ -80,4 +81,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
2
cli/wallet/testdata/testwallet_NEO3.json
vendored
2
cli/wallet/testdata/testwallet_NEO3.json
vendored
|
@ -52,4 +52,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,4 +27,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,6 +48,11 @@ const (
|
|||
TestWalletPath = "../testdata/testwallet.json"
|
||||
TestWalletAccount = "Nfyz4KcsgYepRJw1W5C2uKCi6QWKf7v6gG"
|
||||
|
||||
TestWalletMultiPath = "../testdata/testwallet_multi.json"
|
||||
TestWalletMultiAccount1 = "NgHcPxgEKZQV4QBedzyASJrgiANhJqBVLw"
|
||||
TestWalletMultiAccount2 = "NLvHRfKAifjio2z9HiwLo9ZnpRPHUbAHgH"
|
||||
TestWalletMultiAccount3 = "NcDfG8foJx79XSihcDDrx1df7cHAoJBfXj"
|
||||
|
||||
ValidatorWallet = "../testdata/wallet1_solo.json"
|
||||
ValidatorPass = "one"
|
||||
)
|
||||
|
@ -55,6 +60,10 @@ const (
|
|||
var (
|
||||
ValidatorHash, _ = address.StringToUint160(ValidatorAddr)
|
||||
ValidatorPriv, _ = keys.NewPrivateKeyFromWIF(ValidatorWIF)
|
||||
|
||||
TestWalletMultiAccount1Hash, _ = address.StringToUint160(TestWalletMultiAccount1)
|
||||
TestWalletMultiAccount2Hash, _ = address.StringToUint160(TestWalletMultiAccount2)
|
||||
TestWalletMultiAccount3Hash, _ = address.StringToUint160(TestWalletMultiAccount3)
|
||||
)
|
||||
|
||||
// Executor represents context for a test instance.
|
||||
|
|
2
pkg/consensus/testdata/wallet1.json
vendored
2
pkg/consensus/testdata/wallet1.json
vendored
|
@ -52,4 +52,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
2
pkg/consensus/testdata/wallet2.json
vendored
2
pkg/consensus/testdata/wallet2.json
vendored
|
@ -52,4 +52,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
2
pkg/consensus/testdata/wallet3.json
vendored
2
pkg/consensus/testdata/wallet3.json
vendored
|
@ -52,4 +52,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
2
pkg/consensus/testdata/wallet4.json
vendored
2
pkg/consensus/testdata/wallet4.json
vendored
|
@ -52,4 +52,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
2
pkg/services/notary/testdata/notary1.json
vendored
2
pkg/services/notary/testdata/notary1.json
vendored
|
@ -61,4 +61,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
2
pkg/services/notary/testdata/notary2.json
vendored
2
pkg/services/notary/testdata/notary2.json
vendored
|
@ -27,4 +27,4 @@
|
|||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
10
pkg/services/oracle/testdata/oracle1.json
vendored
10
pkg/services/oracle/testdata/oracle1.json
vendored
|
@ -3,7 +3,7 @@
|
|||
"accounts": [
|
||||
{
|
||||
"address": "NLUCkBS5dtk1h5cedgFoVXqeoCW2UiYNrZ",
|
||||
"key": "6PYVFexrF2CvxJwx3xpoPchHWJpkrcXy5FZjuXckpArgApVm6AEpQwCuKw",
|
||||
"key": "6PYVFexrFDhQ9BewmNFTM8rL5qyq6Zqp3hL2QPZCchJiZQhkctAvUWS3Xa",
|
||||
"label": "",
|
||||
"contract": {
|
||||
"script": "DCEDNxK01e1DnGA+TiGU3H4DKUuGliSz89/NuZCbVvA2u0xBVuezJw==",
|
||||
|
@ -20,11 +20,11 @@
|
|||
}
|
||||
],
|
||||
"scrypt": {
|
||||
"n": 16384,
|
||||
"r": 8,
|
||||
"p": 8
|
||||
"n": 2,
|
||||
"r": 1,
|
||||
"p": 1
|
||||
},
|
||||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
10
pkg/services/oracle/testdata/oracle2.json
vendored
10
pkg/services/oracle/testdata/oracle2.json
vendored
|
@ -3,7 +3,7 @@
|
|||
"accounts": [
|
||||
{
|
||||
"address": "NUkatH1cgvBeQyDwfyEjTqZRgjmXC1d23A",
|
||||
"key": "6PYNvsB8P7Ge5SHth9Ui9ikgkupTfED1g7Ec39gn2YDuuM4LFgQgG4j4i3",
|
||||
"key": "6PYNvsB8NJ3RggwkVxuh8KP6fxuyf9J5bcwrKkLRNaPoea661eEHZyTeVb",
|
||||
"label": "",
|
||||
"contract": {
|
||||
"script": "DCEDEXzwIl4Jhvsj98GYIPFFiedeb1QdP8T79uSBSDNsisxBVuezJw==",
|
||||
|
@ -20,11 +20,11 @@
|
|||
}
|
||||
],
|
||||
"scrypt": {
|
||||
"n": 16384,
|
||||
"r": 8,
|
||||
"p": 8
|
||||
"n": 2,
|
||||
"r": 1,
|
||||
"p": 1
|
||||
},
|
||||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,6 +29,10 @@ var (
|
|||
}
|
||||
|
||||
passwords = []string{"one", "two", "three", "four"}
|
||||
|
||||
// naiveScrypt is naive scrypt parameters used for testing wallets to save
|
||||
// time on accounts decryption.
|
||||
naiveScrypt = keys.ScryptParams{N: 2, R: 1, P: 1}
|
||||
)
|
||||
|
||||
func getKeys(t *testing.T) []*keys.PublicKey {
|
||||
|
@ -42,10 +46,14 @@ func getKeys(t *testing.T) []*keys.PublicKey {
|
|||
return pubs
|
||||
}
|
||||
|
||||
func getAccount(t *testing.T, wif, pass string) *Account {
|
||||
func getNEP2Account(t *testing.T, wif, pass string) *Account {
|
||||
return getAccountWithScrypt(t, wif, pass, keys.NEP2ScryptParams())
|
||||
}
|
||||
|
||||
func getTestingAccount(t *testing.T, wif, pass string) *Account {
|
||||
return getAccountWithScrypt(t, wif, pass, naiveScrypt)
|
||||
}
|
||||
|
||||
func getAccountWithScrypt(t *testing.T, wif, pass string, scrypt keys.ScryptParams) *Account {
|
||||
acc, err := NewAccountFromWIF(wif)
|
||||
require.NoError(t, err)
|
||||
|
@ -59,24 +67,24 @@ func TestRegenerateSoloWallet(t *testing.T) {
|
|||
}
|
||||
walletPath := filepath.Join(dockerWalletDir, "wallet1_solo.json")
|
||||
wif := privnetWIFs[0]
|
||||
acc1 := getAccount(t, wif, "one")
|
||||
acc2 := getAccount(t, wif, "one")
|
||||
acc1 := getNEP2Account(t, wif, "one")
|
||||
acc2 := getNEP2Account(t, wif, "one")
|
||||
require.NoError(t, acc2.ConvertMultisig(3, getKeys(t)))
|
||||
|
||||
acc3 := getAccount(t, wif, "one")
|
||||
acc3 := getNEP2Account(t, wif, "one")
|
||||
require.NoError(t, acc3.ConvertMultisig(1, keys.PublicKeys{getKeys(t)[0]}))
|
||||
|
||||
createWallet(t, walletPath, acc1, acc2, acc3)
|
||||
createNEP2Wallet(t, walletPath, acc1, acc2, acc3)
|
||||
}
|
||||
|
||||
func regenerateWallets(t *testing.T, dir string) {
|
||||
pubs := getKeys(t)
|
||||
for i := range privnetWIFs {
|
||||
acc1 := getAccount(t, privnetWIFs[i], passwords[i])
|
||||
acc2 := getAccount(t, privnetWIFs[i], passwords[i])
|
||||
acc1 := getNEP2Account(t, privnetWIFs[i], passwords[i])
|
||||
acc2 := getNEP2Account(t, privnetWIFs[i], passwords[i])
|
||||
require.NoError(t, acc2.ConvertMultisig(3, pubs))
|
||||
|
||||
createWallet(t, filepath.Join(dir, fmt.Sprintf("wallet%d.json", i+1)), acc1, acc2)
|
||||
createNEP2Wallet(t, filepath.Join(dir, fmt.Sprintf("wallet%d.json", i+1)), acc1, acc2)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,17 +107,17 @@ func TestRegenerateWalletTestdata(t *testing.T) {
|
|||
}
|
||||
const walletDir = "./testdata/"
|
||||
|
||||
acc1 := getAccount(t, privnetWIFs[0], "one")
|
||||
acc2 := getAccount(t, privnetWIFs[0], "one")
|
||||
acc1 := getTestingAccount(t, privnetWIFs[0], "one")
|
||||
acc2 := getTestingAccount(t, privnetWIFs[0], "one")
|
||||
pubs := getKeys(t)
|
||||
require.NoError(t, acc2.ConvertMultisig(3, pubs))
|
||||
|
||||
acc3 := getAccount(t, privnetWIFs[1], "two")
|
||||
acc3 := getTestingAccount(t, privnetWIFs[1], "two")
|
||||
acc3.Default = true
|
||||
|
||||
createWallet(t, filepath.Join(walletDir, "wallet1.json"), acc1, acc2)
|
||||
createTestingWallet(t, filepath.Join(walletDir, "wallet1.json"), acc1, acc2)
|
||||
|
||||
createWallet(t, filepath.Join(walletDir, "wallet2.json"), acc1, acc2, acc3)
|
||||
createTestingWallet(t, filepath.Join(walletDir, "wallet2.json"), acc1, acc2, acc3)
|
||||
}
|
||||
|
||||
func TestRegenerateNotaryWallets(t *testing.T) {
|
||||
|
@ -123,15 +131,13 @@ func TestRegenerateNotaryWallets(t *testing.T) {
|
|||
acc4WIF = "L1ioz93TNt6Nu1aoMpZQ4zgdtgC8ZvJMC6pyHFkrovdR3SFwbn6n"
|
||||
)
|
||||
var walletDir = filepath.Join("..", "services", "notary", "testdata")
|
||||
acc1 := getAccountWithScrypt(t, acc1WIF, "one", naiveScrypt)
|
||||
acc2 := getAccountWithScrypt(t, acc2WIF, "one", naiveScrypt)
|
||||
acc3 := getAccountWithScrypt(t, acc3WIF, "four", naiveScrypt)
|
||||
createTestingWallet(t, filepath.Join(walletDir, "notary1.json"), acc1, acc2, acc3)
|
||||
|
||||
scryptParams := keys.ScryptParams{N: 2, R: 1, P: 1}
|
||||
acc1 := getAccountWithScrypt(t, acc1WIF, "one", scryptParams)
|
||||
acc2 := getAccountWithScrypt(t, acc2WIF, "one", scryptParams)
|
||||
acc3 := getAccountWithScrypt(t, acc3WIF, "four", scryptParams)
|
||||
createWallet(t, filepath.Join(walletDir, "notary1.json"), acc1, acc2, acc3)
|
||||
|
||||
acc4 := getAccountWithScrypt(t, acc4WIF, "two", scryptParams)
|
||||
createWallet(t, filepath.Join(walletDir, "notary2.json"), acc4)
|
||||
acc4 := getAccountWithScrypt(t, acc4WIF, "two", naiveScrypt)
|
||||
createTestingWallet(t, filepath.Join(walletDir, "notary2.json"), acc4)
|
||||
}
|
||||
|
||||
func TestRegenerateOracleWallets(t *testing.T) {
|
||||
|
@ -144,11 +150,11 @@ func TestRegenerateOracleWallets(t *testing.T) {
|
|||
acc2WIF = "KyA8z2MyLCSjJFG3F4SUp85CZ4WJm4qgWihFJZFEDYGEyw8oGcEP"
|
||||
)
|
||||
|
||||
acc1 := getAccount(t, acc1WIF, "one")
|
||||
createWallet(t, filepath.Join(walletDir, "oracle1.json"), acc1)
|
||||
acc1 := getTestingAccount(t, acc1WIF, "one")
|
||||
createTestingWallet(t, filepath.Join(walletDir, "oracle1.json"), acc1)
|
||||
|
||||
acc2 := getAccount(t, acc2WIF, "two")
|
||||
createWallet(t, filepath.Join(walletDir, "oracle2.json"), acc2)
|
||||
acc2 := getTestingAccount(t, acc2WIF, "two")
|
||||
createTestingWallet(t, filepath.Join(walletDir, "oracle2.json"), acc2)
|
||||
}
|
||||
|
||||
func TestRegenerateExamplesWallet(t *testing.T) {
|
||||
|
@ -160,9 +166,9 @@ func TestRegenerateExamplesWallet(t *testing.T) {
|
|||
acc1WIF = "L46dn46AMZY7NQGZHemAdgcMabKon85eme45hgQkAUQBiRacY8MB"
|
||||
)
|
||||
|
||||
acc1 := getAccount(t, acc1WIF, "qwerty")
|
||||
acc1 := getNEP2Account(t, acc1WIF, "qwerty")
|
||||
acc1.Label = "my_account"
|
||||
createWallet(t, walletPath, acc1)
|
||||
createNEP2Wallet(t, walletPath, acc1)
|
||||
}
|
||||
|
||||
func TestRegenerateCLITestwallet(t *testing.T) {
|
||||
|
@ -174,9 +180,32 @@ func TestRegenerateCLITestwallet(t *testing.T) {
|
|||
accWIF = "L23LrQNWELytYLvb5c6dXBDdF2DNPL9RRNWPqppv3roxacSnn8CN"
|
||||
)
|
||||
|
||||
acc := getAccountWithScrypt(t, accWIF, "testpass", keys.ScryptParams{N: 2, R: 1, P: 1})
|
||||
acc := getAccountWithScrypt(t, accWIF, "testpass", naiveScrypt)
|
||||
acc.Label = "kek"
|
||||
createWallet(t, walletPath, acc)
|
||||
createTestingWallet(t, walletPath, acc)
|
||||
}
|
||||
|
||||
func TestRegenerateCLITestwalletMulti(t *testing.T) {
|
||||
if !regenerate {
|
||||
return
|
||||
}
|
||||
const (
|
||||
walletPath = "../../cli/testdata/testwallet_multi.json"
|
||||
accWIF1 = "L2NZQ84s8SuUfyJmtjs7J5a2pZFEVQVVRYDtNsQEyB4RjHnpkorr"
|
||||
pass1 = "one"
|
||||
accWIF2 = "L4pSqPmvbghcM8NY14CNSUzkK92VmSFLKNwAh9TqLqFhTZkxZgsP"
|
||||
pass2 = "two"
|
||||
accWIF3 = "L1eNtPQA8bALqvSgGMNpNR3EYFR15WeNdCZDuiwWYcQ6Q6FfuVro"
|
||||
pass3 = "three"
|
||||
)
|
||||
|
||||
acc1 := getAccountWithScrypt(t, accWIF1, pass1, naiveScrypt)
|
||||
acc1.Label = pass1
|
||||
acc2 := getAccountWithScrypt(t, accWIF2, pass2, naiveScrypt)
|
||||
acc2.Label = pass2
|
||||
acc3 := getAccountWithScrypt(t, accWIF3, pass3, naiveScrypt)
|
||||
acc3.Label = pass3
|
||||
createTestingWallet(t, walletPath, acc1, acc2, acc3)
|
||||
}
|
||||
|
||||
func TestRegenerateCLITestwallet_NEO3(t *testing.T) {
|
||||
|
@ -186,15 +215,28 @@ func TestRegenerateCLITestwallet_NEO3(t *testing.T) {
|
|||
const walletPath = "../../cli/wallet/testdata/testwallet_NEO3.json"
|
||||
|
||||
pubs := getKeys(t)
|
||||
acc1 := getAccount(t, privnetWIFs[0], passwords[0])
|
||||
acc2 := getAccount(t, privnetWIFs[0], passwords[0])
|
||||
acc1 := getNEP2Account(t, privnetWIFs[0], passwords[0])
|
||||
acc2 := getNEP2Account(t, privnetWIFs[0], passwords[0])
|
||||
require.NoError(t, acc2.ConvertMultisig(3, pubs))
|
||||
createWallet(t, walletPath, acc1, acc2)
|
||||
createNEP2Wallet(t, walletPath, acc1, acc2)
|
||||
}
|
||||
|
||||
func createWallet(t *testing.T, path string, accs ...*Account) {
|
||||
// createNEP2Wallet creates wallet with provided accounts and NEP2 scrypt parameters.
|
||||
func createNEP2Wallet(t *testing.T, path string, accs ...*Account) {
|
||||
createWallet(t, path, keys.NEP2ScryptParams(), accs...)
|
||||
}
|
||||
|
||||
// createTestingWallet creates wallet with provided accounts and scrypt parameters with
|
||||
// low values which can be used for testing to save time on accounts decryption.
|
||||
func createTestingWallet(t *testing.T, path string, accs ...*Account) {
|
||||
createWallet(t, path, naiveScrypt, accs...)
|
||||
}
|
||||
|
||||
func createWallet(t *testing.T, path string, scryptParams keys.ScryptParams, accs ...*Account) {
|
||||
w, err := NewWallet(path)
|
||||
require.NoError(t, err)
|
||||
w.Scrypt = scryptParams
|
||||
|
||||
if len(accs) == 0 {
|
||||
t.Fatal("provide at least 1 account")
|
||||
}
|
||||
|
@ -215,17 +257,16 @@ func TestRegenerateCLIWallet1_solo(t *testing.T) {
|
|||
verifyManifestPath = "../../cli/smartcontract/testdata/verify.manifest.json"
|
||||
)
|
||||
|
||||
scrypt := keys.ScryptParams{N: 2, R: 1, P: 1}
|
||||
wif := privnetWIFs[0]
|
||||
acc1 := getAccountWithScrypt(t, wif, "one", scrypt)
|
||||
acc1 := getAccountWithScrypt(t, wif, "one", naiveScrypt)
|
||||
acc1.Default = true
|
||||
acc2 := getAccountWithScrypt(t, wif, "one", scrypt)
|
||||
acc2 := getAccountWithScrypt(t, wif, "one", naiveScrypt)
|
||||
require.NoError(t, acc2.ConvertMultisig(3, getKeys(t)))
|
||||
|
||||
acc3 := getAccountWithScrypt(t, wif, "one", scrypt)
|
||||
acc3 := getAccountWithScrypt(t, wif, "one", naiveScrypt)
|
||||
require.NoError(t, acc3.ConvertMultisig(1, keys.PublicKeys{getKeys(t)[0]}))
|
||||
|
||||
acc4 := getAccountWithScrypt(t, verifyWIF, "pass", scrypt) // deployed verify.go contract
|
||||
acc4 := getAccountWithScrypt(t, verifyWIF, "pass", naiveScrypt) // deployed verify.go contract
|
||||
f, err := os.ReadFile(verifyNEFPath)
|
||||
require.NoError(t, err)
|
||||
nefFile, err := nef.FileFromBytes(f)
|
||||
|
@ -242,5 +283,5 @@ func TestRegenerateCLIWallet1_solo(t *testing.T) {
|
|||
Parameters: []ContractParam{},
|
||||
}
|
||||
acc4.Label = "verify"
|
||||
createWallet(t, walletPath, acc1, acc2, acc3, acc4)
|
||||
createTestingWallet(t, walletPath, acc1, acc2, acc3, acc4)
|
||||
}
|
||||
|
|
12
pkg/wallet/testdata/wallet1.json
vendored
12
pkg/wallet/testdata/wallet1.json
vendored
|
@ -3,7 +3,7 @@
|
|||
"accounts": [
|
||||
{
|
||||
"address": "Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn",
|
||||
"key": "6PYM8VdX2BSm7BSXKzV4Fz6S3R9cDLLWNrD9nMjxW352jEv3fsC8N3wNLY",
|
||||
"key": "6PYM8VdX3hY4B51UJxmm8D41RQMbpJT8aYHibyQ67gjkUPmvQgu51Y5UQR",
|
||||
"label": "",
|
||||
"contract": {
|
||||
"script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBVuezJw==",
|
||||
|
@ -20,7 +20,7 @@
|
|||
},
|
||||
{
|
||||
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
|
||||
"key": "6PYM8VdX2BSm7BSXKzV4Fz6S3R9cDLLWNrD9nMjxW352jEv3fsC8N3wNLY",
|
||||
"key": "6PYM8VdX3hY4B51UJxmm8D41RQMbpJT8aYHibyQ67gjkUPmvQgu51Y5UQR",
|
||||
"label": "",
|
||||
"contract": {
|
||||
"script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6",
|
||||
|
@ -45,11 +45,11 @@
|
|||
}
|
||||
],
|
||||
"scrypt": {
|
||||
"n": 16384,
|
||||
"r": 8,
|
||||
"p": 8
|
||||
"n": 2,
|
||||
"r": 1,
|
||||
"p": 1
|
||||
},
|
||||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
14
pkg/wallet/testdata/wallet2.json
vendored
14
pkg/wallet/testdata/wallet2.json
vendored
|
@ -3,7 +3,7 @@
|
|||
"accounts": [
|
||||
{
|
||||
"address": "Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn",
|
||||
"key": "6PYM8VdX2BSm7BSXKzV4Fz6S3R9cDLLWNrD9nMjxW352jEv3fsC8N3wNLY",
|
||||
"key": "6PYM8VdX3hY4B51UJxmm8D41RQMbpJT8aYHibyQ67gjkUPmvQgu51Y5UQR",
|
||||
"label": "",
|
||||
"contract": {
|
||||
"script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBVuezJw==",
|
||||
|
@ -20,7 +20,7 @@
|
|||
},
|
||||
{
|
||||
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
|
||||
"key": "6PYM8VdX2BSm7BSXKzV4Fz6S3R9cDLLWNrD9nMjxW352jEv3fsC8N3wNLY",
|
||||
"key": "6PYM8VdX3hY4B51UJxmm8D41RQMbpJT8aYHibyQ67gjkUPmvQgu51Y5UQR",
|
||||
"label": "",
|
||||
"contract": {
|
||||
"script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6",
|
||||
|
@ -45,7 +45,7 @@
|
|||
},
|
||||
{
|
||||
"address": "NMUedC8TSV2rE17wGguSvPk9XcmHSaT275",
|
||||
"key": "6PYSYoZaxqDu5vqvm7yUFT3sPJJFwyLyYDnp8zwj1YVPcBWxacz64bNX59",
|
||||
"key": "6PYSYoZawnSyrpXJTu9aN7uXFd1HTisrtimxMs7xkEnqe2zztLrMvFZCtT",
|
||||
"label": "",
|
||||
"contract": {
|
||||
"script": "DCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG5BVuezJw==",
|
||||
|
@ -62,11 +62,11 @@
|
|||
}
|
||||
],
|
||||
"scrypt": {
|
||||
"n": 16384,
|
||||
"r": 8,
|
||||
"p": 8
|
||||
"n": 2,
|
||||
"r": 1,
|
||||
"p": 1
|
||||
},
|
||||
"extra": {
|
||||
"Tokens": null
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue