-
Notifications
You must be signed in to change notification settings - Fork 1
/
transfer_test.go
54 lines (42 loc) · 1.58 KB
/
transfer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package erc20_test
import (
"context"
"io/ioutil"
"testing"
"github.com/centrifuge/go-substrate-rpc-client/v3/signature"
"github.com/patractlabs/go-patract/contracts/erc20"
"github.com/patractlabs/go-patract/rpc"
"github.com/patractlabs/go-patract/test"
"github.com/patractlabs/go-patract/types"
"github.com/patractlabs/go-patract/utils/log"
"github.com/stretchr/testify/require"
)
func TestTransfer(t *testing.T) {
test.ByNodeEnv(t, func(logger log.Logger, env test.Env) {
require := require.New(t)
contractAccountID := initERC20(t, logger, env, signature.TestKeyringPairAlice)
rpcAPI, err := rpc.NewContractAPI(env.URL())
require.Nil(err)
metaBz, err := ioutil.ReadFile(erc20MetaPath)
require.Nil(err)
rpcAPI.WithMetaData(metaBz)
rpcAPI.WithLogger(logger)
erc20API := erc20.New(rpcAPI, contractAccountID)
// transfer alice to bob
ctx := rpc.NewCtx(context.Background()).WithFrom(signature.TestKeyringPairAlice)
aliceTotal, err := erc20API.BalanceOf(ctx, test.AliceAccountID)
require.Nil(err)
require.Equalf(*aliceTotal.Int, totalSupply, "alice should be total supply")
// transfer
amt2Bob := types.NewBalanceByU64(100)
_, err = erc20API.Transfer(ctx, bob, amt2Bob)
require.Nil(err)
bobBalance, err := erc20API.BalanceOf(ctx, bob)
require.Nil(err)
require.Equalf(bobBalance, amt2Bob, "bob Balance should be amt2Bob")
aliceNewTotal, err := erc20API.BalanceOf(ctx, test.AliceAccountID)
require.Nil(err)
require.Equalf(aliceTotal.Int, aliceNewTotal.Int.Add(aliceNewTotal.Int, amt2Bob.Int),
"alice new add transfer should be alice old")
})
}