Skip to content

Commit

Permalink
test(wallet): update tests for GetNewAddress API (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f authored Jun 18, 2024
1 parent 07310a7 commit efa38ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
25 changes: 19 additions & 6 deletions wallet/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,25 @@ func TestAllImportedPrivateKeysAddresses(t *testing.T) {
func TestNewBLSAccountAddress(t *testing.T) {
td := setup(t)

t.Run("Ok", func(t *testing.T) {
addressInfo, err := td.vault.NewBLSAccountAddress("new-addr")
assert.NoError(t, err)
assert.True(t, td.vault.Contains(addressInfo.Address))
assert.Equal(t, td.vault.Label(addressInfo.Address), "new-addr")
})
label := td.RandString(16)
addressInfo, err := td.vault.NewBLSAccountAddress(label)
assert.NoError(t, err)
assert.NotEmpty(t, addressInfo.Address)
assert.NotEmpty(t, addressInfo.PublicKey)
assert.Contains(t, addressInfo.Path, "m/12381'/21888'/2'")
assert.Equal(t, addressInfo.Label, label)
}

func TestNewValidatorAddress(t *testing.T) {
td := setup(t)

label := td.RandString(16)
addressInfo, err := td.vault.NewValidatorAddress(label)
assert.NoError(t, err)
assert.NotEmpty(t, addressInfo.Address)
assert.NotEmpty(t, addressInfo.PublicKey)
assert.Contains(t, addressInfo.Path, "m/12381'/21888'/1'")
assert.Equal(t, addressInfo.Label, label)
}

func TestRecover(t *testing.T) {
Expand Down
14 changes: 9 additions & 5 deletions www/grpc/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,14 @@ func TestGetNewAddress(t *testing.T) {
res, err := client.GetNewAddress(context.Background(),
&pactus.GetNewAddressRequest{
WalletName: wltName,
AddressType: 2,
Label: "bls",
AddressType: pactus.AddressType_ADDRESS_TYPE_BLS_ACCOUNT,
Label: "bls-account",
})
assert.Nil(t, err)
assert.Equal(t, wltName, res.WalletName)
assert.Equal(t, "bls", res.AddressInfo.Label)
assert.NotEmpty(t, res.AddressInfo.PublicKey)
assert.NotEmpty(t, res.AddressInfo.Path)
assert.Equal(t, "bls-account", res.AddressInfo.Label)

_, err = client.UnloadWallet(context.Background(),
&pactus.UnloadWalletRequest{
Expand All @@ -325,11 +327,13 @@ func TestGetNewAddress(t *testing.T) {
res, err := client.GetNewAddress(context.Background(),
&pactus.GetNewAddressRequest{
WalletName: wltName,
AddressType: 1,
AddressType: pactus.AddressType_ADDRESS_TYPE_VALIDATOR,
Label: "validator",
})
assert.Nil(t, err)
assert.Equal(t, wltName, res.WalletName)
assert.NotEmpty(t, res.AddressInfo.PublicKey)
assert.NotEmpty(t, res.AddressInfo.Path)
assert.Equal(t, "validator", res.AddressInfo.Label)

_, err = client.UnloadWallet(context.Background(),
Expand All @@ -349,7 +353,7 @@ func TestGetNewAddress(t *testing.T) {
res, err := client.GetNewAddress(context.Background(),
&pactus.GetNewAddressRequest{
WalletName: wltName,
AddressType: 0,
AddressType: pactus.AddressType_ADDRESS_TYPE_TREASURY,
Label: "treasury",
})
assert.NotNil(t, err)
Expand Down

0 comments on commit efa38ed

Please sign in to comment.