Improve address and shardID validation for the wallet (#1702)
* - Improve validation of sender and receiving addresses - Improve validation of sender and receiving shardIDs - Run tests using go test cmd/client/wallet_validation/validation_test.go * - Fix linting issues - Fix test issue - Move from wallet_validation to validation * Update test: - The local profile might eventually get updated to include more than 2 shards, in that case the test will fail. Use obviously invalid values (-1 / 99) for now. * - Fix order of imports (std should come first) - Fix typo * Fix goimports linting * Fix go import linting (again...) * Fix go import linting * Fix goimport linting * Fix go import linting (sigh...) * Fix goimports formatting using go fmt * Update validation checking, also validate addresses supplied (--address) to: - getFreeToken - format - balances * Merge remote master into branch * - Move wallet validation to cmd/client/wallet/main.go - Move validation test to cmd/client/wallet/validation_test.go * Refactor validateAddresspull/1722/head testnet-20191011.0
parent
1d5634427b
commit
a7c04bfc4b
@ -0,0 +1,51 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/harmony-one/harmony/internal/common" |
||||
) |
||||
|
||||
func TestIsValidAddress(t *testing.T) { |
||||
tests := []struct { |
||||
str string |
||||
exp bool |
||||
}{ |
||||
{"one1ay37rp2pc3kjarg7a322vu3sa8j9puahg679z3", true}, |
||||
{"0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", true}, |
||||
{"onefoofoo", false}, |
||||
{"0xbarbar", false}, |
||||
{"dsasdadsasaadsas", false}, |
||||
{"32312123213213212321", false}, |
||||
} |
||||
|
||||
for _, test := range tests { |
||||
valid, _ := validateAddress(test.str, common.ParseAddr(test.str), "sender") |
||||
|
||||
if valid != test.exp { |
||||
t.Errorf("validateAddress(\"%s\") returned %v, expected %v", test.str, valid, test.exp) |
||||
} |
||||
} |
||||
} |
||||
|
||||
func TestIsValidShard(t *testing.T) { |
||||
readProfile("local") |
||||
|
||||
tests := []struct { |
||||
shardID int |
||||
exp bool |
||||
}{ |
||||
{0, true}, |
||||
{1, true}, |
||||
{-1, false}, |
||||
{99, false}, |
||||
} |
||||
|
||||
for _, test := range tests { |
||||
valid := validShard(test.shardID, walletProfile.Shards) |
||||
|
||||
if valid != test.exp { |
||||
t.Errorf("validShard(%d) returned %v, expected %v", test.shardID, valid, test.exp) |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue