Merge pull request #3332 from nspcc-dev/fix-nep17-test

cli: fix race in TestNEP17Balance
This commit is contained in:
Roman Khimov 2024-03-03 15:27:25 +03:00 committed by GitHub
commit 8d67f17943
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 240 additions and 122 deletions

View file

@ -16,7 +16,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
}, },
{ {
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq", "address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
@ -41,7 +41,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
} }
], ],
"scrypt": { "scrypt": {

View file

@ -16,7 +16,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
}, },
{ {
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq", "address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
@ -41,7 +41,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
}, },
{ {
"address": "NfgHwwTi3wHAS8aFAN243C5vGbkYDpqLHP", "address": "NfgHwwTi3wHAS8aFAN243C5vGbkYDpqLHP",
@ -58,7 +58,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
} }
], ],
"scrypt": { "scrypt": {

View file

@ -16,7 +16,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
}, },
{ {
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq", "address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
@ -41,7 +41,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
} }
], ],
"scrypt": { "scrypt": {

View file

@ -16,7 +16,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
}, },
{ {
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq", "address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
@ -41,7 +41,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
} }
], ],
"scrypt": { "scrypt": {

View file

@ -16,7 +16,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
}, },
{ {
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq", "address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
@ -41,7 +41,7 @@
"deployed": false "deployed": false
}, },
"lock": false, "lock": false,
"isdefault": false "isDefault": false
} }
], ],
"scrypt": { "scrypt": {

View file

@ -19,19 +19,34 @@ import (
func TestNEP17Balance(t *testing.T) { func TestNEP17Balance(t *testing.T) {
e := testcli.NewExecutor(t, true) 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"} cmdbalance := []string{"neo-go", "wallet", "nep17", "balance"}
cmdbase := append(cmdbalance, cmdbase := append(cmdbalance,
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0], "--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) { t.Run("excessive parameters", func(t *testing.T) {
e.RunWithError(t, append(cmd, "--token", "NEO", "gas")...) e.RunWithError(t, append(cmd, "--token", "NEO", "gas")...)
}) })
t.Run("NEO", func(t *testing.T) { 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) { 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*NEO:\\s+NeoToken \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)")
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$") e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$")
e.CheckNextLine(t, "^\\s*Updated\\s*:\\s*"+strconv.FormatUint(uint64(index), 10)) 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) { t.Run("GAS", func(t *testing.T) {
e.Run(t, append(cmd, "--token", "GAS")...) 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()+"\\)") 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()+"$") e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(b.Int64()).String()+"$")
}) })
t.Run("zero balance of known token", func(t *testing.T) { t.Run("zero balance of known token", func(t *testing.T) {
e.Run(t, append(cmdbase, []string{"--token", "NEO"}...)...) e.Run(t, append(cmdbase, []string{"--token", "NEO", "--address", testcli.TestWalletMultiAccount2}...)...)
addr1, err := address.StringToUint160("Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn") e.CheckNextLine(t, "^Account "+testcli.TestWalletMultiAccount2)
require.NoError(t, err)
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr1))
e.CheckNextLine(t, "^\\s*NEO:\\s+NeoToken \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)") 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*Amount\\s*:\\s*"+fixedn.Fixed8(0).String()+"$")
e.CheckNextLine(t, "^\\s*Updated:") e.CheckNextLine(t, "^\\s*Updated:")
e.CheckNextLine(t, "^\\s*$") e.CheckEOF(t)
}) })
t.Run("all accounts", func(t *testing.T) { t.Run("all accounts", func(t *testing.T) {
e.Run(t, cmdbase...) 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") e.CheckNextLine(t, "^Account "+testcli.TestWalletMultiAccount1)
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))
// The order of assets is undefined. // The order of assets is undefined.
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
line := e.GetNextLine(t) line := e.GetNextLine(t)
if strings.Contains(line, "GAS") { if strings.Contains(line, "GAS") {
e.CheckLine(t, line, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)") 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*Amount\\s*:\\s*"+fixedn.Fixed8(balance.Int64()).String()+"$")
e.CheckNextLine(t, "^\\s*Updated:") e.CheckNextLine(t, "^\\s*Updated:")
} else { } 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.CheckLine(t, line, "^\\s*NEO:\\s+NeoToken \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)")
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+balance.String()+"$") 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*Updated\\s*:\\s*"+strconv.FormatUint(uint64(index), 10))
} }
} }
e.CheckNextLine(t, "^\\s*$") e.CheckNextLine(t, "^\\s*$")
addr4, err := address.StringToUint160("NiFxRcC5Anz9pmqQyMHh5vamBUZDbRRRzA") // deployed verify.go contract
require.NoError(t, err) e.CheckNextLine(t, "^Account "+testcli.TestWalletMultiAccount2)
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr4)) 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) e.CheckEOF(t)
}) })
t.Run("Bad token", func(t *testing.T) { t.Run("Bad token", func(t *testing.T) {
e.Run(t, append(cmd, "--token", "kek")...) 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.CheckNextLine(t, `^\s*Can't find data for "kek" token\s*`)
e.CheckEOF(t) e.CheckEOF(t)
}) })

64
cli/testdata/testwallet_multi.json vendored Normal file
View 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
}
}

View file

@ -65,6 +65,7 @@
"key": "6PYSATFztBa3CHjSR6sLAKungUEAbQUCVE16KzmaQQ38gLeYGZ9Knd5mGv", "key": "6PYSATFztBa3CHjSR6sLAKungUEAbQUCVE16KzmaQQ38gLeYGZ9Knd5mGv",
"label": "verify", "label": "verify",
"contract": { "contract": {
"script": "VwEAEUBXAANA",
"parameters": [], "parameters": [],
"deployed": true "deployed": true
}, },

View file

@ -48,6 +48,11 @@ const (
TestWalletPath = "../testdata/testwallet.json" TestWalletPath = "../testdata/testwallet.json"
TestWalletAccount = "Nfyz4KcsgYepRJw1W5C2uKCi6QWKf7v6gG" TestWalletAccount = "Nfyz4KcsgYepRJw1W5C2uKCi6QWKf7v6gG"
TestWalletMultiPath = "../testdata/testwallet_multi.json"
TestWalletMultiAccount1 = "NgHcPxgEKZQV4QBedzyASJrgiANhJqBVLw"
TestWalletMultiAccount2 = "NLvHRfKAifjio2z9HiwLo9ZnpRPHUbAHgH"
TestWalletMultiAccount3 = "NcDfG8foJx79XSihcDDrx1df7cHAoJBfXj"
ValidatorWallet = "../testdata/wallet1_solo.json" ValidatorWallet = "../testdata/wallet1_solo.json"
ValidatorPass = "one" ValidatorPass = "one"
) )
@ -55,6 +60,10 @@ const (
var ( var (
ValidatorHash, _ = address.StringToUint160(ValidatorAddr) ValidatorHash, _ = address.StringToUint160(ValidatorAddr)
ValidatorPriv, _ = keys.NewPrivateKeyFromWIF(ValidatorWIF) ValidatorPriv, _ = keys.NewPrivateKeyFromWIF(ValidatorWIF)
TestWalletMultiAccount1Hash, _ = address.StringToUint160(TestWalletMultiAccount1)
TestWalletMultiAccount2Hash, _ = address.StringToUint160(TestWalletMultiAccount2)
TestWalletMultiAccount3Hash, _ = address.StringToUint160(TestWalletMultiAccount3)
) )
// Executor represents context for a test instance. // Executor represents context for a test instance.

View file

@ -3,7 +3,7 @@
"accounts": [ "accounts": [
{ {
"address": "NLUCkBS5dtk1h5cedgFoVXqeoCW2UiYNrZ", "address": "NLUCkBS5dtk1h5cedgFoVXqeoCW2UiYNrZ",
"key": "6PYVFexrF2CvxJwx3xpoPchHWJpkrcXy5FZjuXckpArgApVm6AEpQwCuKw", "key": "6PYVFexrFDhQ9BewmNFTM8rL5qyq6Zqp3hL2QPZCchJiZQhkctAvUWS3Xa",
"label": "", "label": "",
"contract": { "contract": {
"script": "DCEDNxK01e1DnGA+TiGU3H4DKUuGliSz89/NuZCbVvA2u0xBVuezJw==", "script": "DCEDNxK01e1DnGA+TiGU3H4DKUuGliSz89/NuZCbVvA2u0xBVuezJw==",
@ -20,9 +20,9 @@
} }
], ],
"scrypt": { "scrypt": {
"n": 16384, "n": 2,
"r": 8, "r": 1,
"p": 8 "p": 1
}, },
"extra": { "extra": {
"Tokens": null "Tokens": null

View file

@ -3,7 +3,7 @@
"accounts": [ "accounts": [
{ {
"address": "NUkatH1cgvBeQyDwfyEjTqZRgjmXC1d23A", "address": "NUkatH1cgvBeQyDwfyEjTqZRgjmXC1d23A",
"key": "6PYNvsB8P7Ge5SHth9Ui9ikgkupTfED1g7Ec39gn2YDuuM4LFgQgG4j4i3", "key": "6PYNvsB8NJ3RggwkVxuh8KP6fxuyf9J5bcwrKkLRNaPoea661eEHZyTeVb",
"label": "", "label": "",
"contract": { "contract": {
"script": "DCEDEXzwIl4Jhvsj98GYIPFFiedeb1QdP8T79uSBSDNsisxBVuezJw==", "script": "DCEDEXzwIl4Jhvsj98GYIPFFiedeb1QdP8T79uSBSDNsisxBVuezJw==",
@ -20,9 +20,9 @@
} }
], ],
"scrypt": { "scrypt": {
"n": 16384, "n": 2,
"r": 8, "r": 1,
"p": 8 "p": 1
}, },
"extra": { "extra": {
"Tokens": null "Tokens": null

View file

@ -29,6 +29,10 @@ var (
} }
passwords = []string{"one", "two", "three", "four"} 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 { func getKeys(t *testing.T) []*keys.PublicKey {
@ -42,10 +46,14 @@ func getKeys(t *testing.T) []*keys.PublicKey {
return pubs 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()) 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 { func getAccountWithScrypt(t *testing.T, wif, pass string, scrypt keys.ScryptParams) *Account {
acc, err := NewAccountFromWIF(wif) acc, err := NewAccountFromWIF(wif)
require.NoError(t, err) require.NoError(t, err)
@ -59,24 +67,24 @@ func TestRegenerateSoloWallet(t *testing.T) {
} }
walletPath := filepath.Join(dockerWalletDir, "wallet1_solo.json") walletPath := filepath.Join(dockerWalletDir, "wallet1_solo.json")
wif := privnetWIFs[0] wif := privnetWIFs[0]
acc1 := getAccount(t, wif, "one") acc1 := getNEP2Account(t, wif, "one")
acc2 := getAccount(t, wif, "one") acc2 := getNEP2Account(t, wif, "one")
require.NoError(t, acc2.ConvertMultisig(3, getKeys(t))) 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]})) 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) { func regenerateWallets(t *testing.T, dir string) {
pubs := getKeys(t) pubs := getKeys(t)
for i := range privnetWIFs { for i := range privnetWIFs {
acc1 := getAccount(t, privnetWIFs[i], passwords[i]) acc1 := getNEP2Account(t, privnetWIFs[i], passwords[i])
acc2 := getAccount(t, privnetWIFs[i], passwords[i]) acc2 := getNEP2Account(t, privnetWIFs[i], passwords[i])
require.NoError(t, acc2.ConvertMultisig(3, pubs)) 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/" const walletDir = "./testdata/"
acc1 := getAccount(t, privnetWIFs[0], "one") acc1 := getTestingAccount(t, privnetWIFs[0], "one")
acc2 := getAccount(t, privnetWIFs[0], "one") acc2 := getTestingAccount(t, privnetWIFs[0], "one")
pubs := getKeys(t) pubs := getKeys(t)
require.NoError(t, acc2.ConvertMultisig(3, pubs)) require.NoError(t, acc2.ConvertMultisig(3, pubs))
acc3 := getAccount(t, privnetWIFs[1], "two") acc3 := getTestingAccount(t, privnetWIFs[1], "two")
acc3.Default = true 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) { func TestRegenerateNotaryWallets(t *testing.T) {
@ -123,15 +131,13 @@ func TestRegenerateNotaryWallets(t *testing.T) {
acc4WIF = "L1ioz93TNt6Nu1aoMpZQ4zgdtgC8ZvJMC6pyHFkrovdR3SFwbn6n" acc4WIF = "L1ioz93TNt6Nu1aoMpZQ4zgdtgC8ZvJMC6pyHFkrovdR3SFwbn6n"
) )
var walletDir = filepath.Join("..", "services", "notary", "testdata") 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} acc4 := getAccountWithScrypt(t, acc4WIF, "two", naiveScrypt)
acc1 := getAccountWithScrypt(t, acc1WIF, "one", scryptParams) createTestingWallet(t, filepath.Join(walletDir, "notary2.json"), acc4)
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)
} }
func TestRegenerateOracleWallets(t *testing.T) { func TestRegenerateOracleWallets(t *testing.T) {
@ -144,11 +150,11 @@ func TestRegenerateOracleWallets(t *testing.T) {
acc2WIF = "KyA8z2MyLCSjJFG3F4SUp85CZ4WJm4qgWihFJZFEDYGEyw8oGcEP" acc2WIF = "KyA8z2MyLCSjJFG3F4SUp85CZ4WJm4qgWihFJZFEDYGEyw8oGcEP"
) )
acc1 := getAccount(t, acc1WIF, "one") acc1 := getTestingAccount(t, acc1WIF, "one")
createWallet(t, filepath.Join(walletDir, "oracle1.json"), acc1) createTestingWallet(t, filepath.Join(walletDir, "oracle1.json"), acc1)
acc2 := getAccount(t, acc2WIF, "two") acc2 := getTestingAccount(t, acc2WIF, "two")
createWallet(t, filepath.Join(walletDir, "oracle2.json"), acc2) createTestingWallet(t, filepath.Join(walletDir, "oracle2.json"), acc2)
} }
func TestRegenerateExamplesWallet(t *testing.T) { func TestRegenerateExamplesWallet(t *testing.T) {
@ -160,9 +166,9 @@ func TestRegenerateExamplesWallet(t *testing.T) {
acc1WIF = "L46dn46AMZY7NQGZHemAdgcMabKon85eme45hgQkAUQBiRacY8MB" acc1WIF = "L46dn46AMZY7NQGZHemAdgcMabKon85eme45hgQkAUQBiRacY8MB"
) )
acc1 := getAccount(t, acc1WIF, "qwerty") acc1 := getNEP2Account(t, acc1WIF, "qwerty")
acc1.Label = "my_account" acc1.Label = "my_account"
createWallet(t, walletPath, acc1) createNEP2Wallet(t, walletPath, acc1)
} }
func TestRegenerateCLITestwallet(t *testing.T) { func TestRegenerateCLITestwallet(t *testing.T) {
@ -174,9 +180,32 @@ func TestRegenerateCLITestwallet(t *testing.T) {
accWIF = "L23LrQNWELytYLvb5c6dXBDdF2DNPL9RRNWPqppv3roxacSnn8CN" accWIF = "L23LrQNWELytYLvb5c6dXBDdF2DNPL9RRNWPqppv3roxacSnn8CN"
) )
acc := getAccountWithScrypt(t, accWIF, "testpass", keys.ScryptParams{N: 2, R: 1, P: 1}) acc := getAccountWithScrypt(t, accWIF, "testpass", naiveScrypt)
acc.Label = "kek" 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) { func TestRegenerateCLITestwallet_NEO3(t *testing.T) {
@ -186,15 +215,28 @@ func TestRegenerateCLITestwallet_NEO3(t *testing.T) {
const walletPath = "../../cli/wallet/testdata/testwallet_NEO3.json" const walletPath = "../../cli/wallet/testdata/testwallet_NEO3.json"
pubs := getKeys(t) pubs := getKeys(t)
acc1 := getAccount(t, privnetWIFs[0], passwords[0]) acc1 := getNEP2Account(t, privnetWIFs[0], passwords[0])
acc2 := getAccount(t, privnetWIFs[0], passwords[0]) acc2 := getNEP2Account(t, privnetWIFs[0], passwords[0])
require.NoError(t, acc2.ConvertMultisig(3, pubs)) 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) w, err := NewWallet(path)
require.NoError(t, err) require.NoError(t, err)
w.Scrypt = scryptParams
if len(accs) == 0 { if len(accs) == 0 {
t.Fatal("provide at least 1 account") t.Fatal("provide at least 1 account")
} }
@ -215,17 +257,16 @@ func TestRegenerateCLIWallet1_solo(t *testing.T) {
verifyManifestPath = "../../cli/smartcontract/testdata/verify.manifest.json" verifyManifestPath = "../../cli/smartcontract/testdata/verify.manifest.json"
) )
scrypt := keys.ScryptParams{N: 2, R: 1, P: 1}
wif := privnetWIFs[0] wif := privnetWIFs[0]
acc1 := getAccountWithScrypt(t, wif, "one", scrypt) acc1 := getAccountWithScrypt(t, wif, "one", naiveScrypt)
acc1.Default = true acc1.Default = true
acc2 := getAccountWithScrypt(t, wif, "one", scrypt) acc2 := getAccountWithScrypt(t, wif, "one", naiveScrypt)
require.NoError(t, acc2.ConvertMultisig(3, getKeys(t))) 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]})) 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) f, err := os.ReadFile(verifyNEFPath)
require.NoError(t, err) require.NoError(t, err)
nefFile, err := nef.FileFromBytes(f) nefFile, err := nef.FileFromBytes(f)
@ -242,5 +283,5 @@ func TestRegenerateCLIWallet1_solo(t *testing.T) {
Parameters: []ContractParam{}, Parameters: []ContractParam{},
} }
acc4.Label = "verify" acc4.Label = "verify"
createWallet(t, walletPath, acc1, acc2, acc3, acc4) createTestingWallet(t, walletPath, acc1, acc2, acc3, acc4)
} }

View file

@ -3,7 +3,7 @@
"accounts": [ "accounts": [
{ {
"address": "Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn", "address": "Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn",
"key": "6PYM8VdX2BSm7BSXKzV4Fz6S3R9cDLLWNrD9nMjxW352jEv3fsC8N3wNLY", "key": "6PYM8VdX3hY4B51UJxmm8D41RQMbpJT8aYHibyQ67gjkUPmvQgu51Y5UQR",
"label": "", "label": "",
"contract": { "contract": {
"script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBVuezJw==", "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBVuezJw==",
@ -20,7 +20,7 @@
}, },
{ {
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq", "address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
"key": "6PYM8VdX2BSm7BSXKzV4Fz6S3R9cDLLWNrD9nMjxW352jEv3fsC8N3wNLY", "key": "6PYM8VdX3hY4B51UJxmm8D41RQMbpJT8aYHibyQ67gjkUPmvQgu51Y5UQR",
"label": "", "label": "",
"contract": { "contract": {
"script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6", "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6",
@ -45,9 +45,9 @@
} }
], ],
"scrypt": { "scrypt": {
"n": 16384, "n": 2,
"r": 8, "r": 1,
"p": 8 "p": 1
}, },
"extra": { "extra": {
"Tokens": null "Tokens": null

View file

@ -3,7 +3,7 @@
"accounts": [ "accounts": [
{ {
"address": "Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn", "address": "Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn",
"key": "6PYM8VdX2BSm7BSXKzV4Fz6S3R9cDLLWNrD9nMjxW352jEv3fsC8N3wNLY", "key": "6PYM8VdX3hY4B51UJxmm8D41RQMbpJT8aYHibyQ67gjkUPmvQgu51Y5UQR",
"label": "", "label": "",
"contract": { "contract": {
"script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBVuezJw==", "script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBVuezJw==",
@ -20,7 +20,7 @@
}, },
{ {
"address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq", "address": "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq",
"key": "6PYM8VdX2BSm7BSXKzV4Fz6S3R9cDLLWNrD9nMjxW352jEv3fsC8N3wNLY", "key": "6PYM8VdX3hY4B51UJxmm8D41RQMbpJT8aYHibyQ67gjkUPmvQgu51Y5UQR",
"label": "", "label": "",
"contract": { "contract": {
"script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6", "script": "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6",
@ -45,7 +45,7 @@
}, },
{ {
"address": "NMUedC8TSV2rE17wGguSvPk9XcmHSaT275", "address": "NMUedC8TSV2rE17wGguSvPk9XcmHSaT275",
"key": "6PYSYoZaxqDu5vqvm7yUFT3sPJJFwyLyYDnp8zwj1YVPcBWxacz64bNX59", "key": "6PYSYoZawnSyrpXJTu9aN7uXFd1HTisrtimxMs7xkEnqe2zztLrMvFZCtT",
"label": "", "label": "",
"contract": { "contract": {
"script": "DCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG5BVuezJw==", "script": "DCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG5BVuezJw==",
@ -62,9 +62,9 @@
} }
], ],
"scrypt": { "scrypt": {
"n": 16384, "n": 2,
"r": 8, "r": 1,
"p": 8 "p": 1
}, },
"extra": { "extra": {
"Tokens": null "Tokens": null