token_test.gno
0.98 Kb · 51 lines
1package transfer_test
2
3import (
4 "chain"
5 "testing"
6
7 "gno.land/p/nt/uassert/v0"
8 "gno.land/p/nt/urequire/v0"
9 "gno.land/r/aib/ibc/apps/transfer"
10)
11
12func TestTokenToCoin(t *testing.T) {
13 const (
14 tokenDenom = "atom/pool"
15 tokenAmount = "100"
16 )
17 testCases := []struct {
18 name string
19 token transfer.Token
20 expCoin chain.Coin
21 expError string
22 }{
23 {
24 "success: convert token to coin",
25 transfer.NewToken(tokenDenom, tokenAmount),
26 chain.NewCoin(tokenDenom, 100),
27 "",
28 },
29 {
30 "failure: invalid amount string",
31 transfer.NewToken(tokenDenom, "value"),
32 chain.Coin{},
33 "unable to parse amount \"value\" into int64",
34 },
35 }
36
37 for _, tc := range testCases {
38 t.Run(tc.name, func(t *testing.T) {
39
40 coin, err := tc.token.ToCoin()
41
42 if tc.expError == "" {
43 urequire.NoError(t, err, tc.name)
44 return
45 }
46 urequire.ErrorContains(t, err, tc.expError)
47 uassert.Equal(t, tc.expCoin.Amount, coin.Amount)
48 uassert.Equal(t, tc.expCoin.Denom, coin.Denom)
49 })
50 }
51}