-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
93 lines (77 loc) · 2.19 KB
/
client_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// +build integration
package client
import (
"bufio"
"os"
"testing"
"time"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keys"
crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/dfinance/dnode/cmd/config"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)
var (
DefaultCLIHome = os.ExpandEnv("$HOME/.dncli")
)
func init() {
cfg := sdk.GetConfig()
config.InitBechPrefixes(cfg)
cfg.Seal()
}
func makeKeybaseAndClient(t *testing.T) (crkeys.Keybase, DnodeClient) {
inBuf := bufio.NewReader(os.Stdin)
kb, err := keys.NewKeyring("dfinance", "os", viper.GetString(flags.FlagHome), inBuf)
require.NoError(t, err)
txBuiler := auth.TxBuilder{}.
WithKeybase(kb).
WithChainID("dn-testnet").
WithFees("1dfi").
WithGas(500000)
client := New(WithTxBuilder(txBuiler), WithAccountName("oracle1"))
require.NoError(t, err)
return kb, client
}
func TestDnodeClient_PostPrices(t *testing.T) {
kb, cl := makeKeybaseAndClient(t)
ki, err := kb.Get("oracle1")
require.NoError(t, err)
acc, err := cl.Auth().Account(ki.GetAddress())
require.NoError(t, err)
result, err := cl.WithAccount(acc).Oracle().PostPrices([]MsgPostPrice{
{
From: ki.GetAddress(),
AssetCode: "eth_usdt",
Price: sdk.NewInt(1000000),
ReceivedAt: time.Now(),
},
{
From: ki.GetAddress(),
AssetCode: "dfi_eth",
Price: sdk.NewInt(1200000),
ReceivedAt: time.Now(),
},
})
require.NoError(t, err)
require.True(t, result.Code == 0)
assets, err := cl.Oracle().Assets()
require.NoError(t, err)
require.True(t, len(assets) > 0)
}
func TestDnodeClient_IssueCurrency(t *testing.T) {
kb, cl := makeKeybaseAndClient(t)
ki, err := kb.Get("validator1")
require.NoError(t, err)
acc, err := cl.Auth().Account(ki.GetAddress())
issueMsg := MsgIssueCurrency{
ID: "Issuing USDT",
Coin: sdk.NewCoin("USDT", sdk.NewInt(1000)),
Payee: acc.GetAddress(),
}
resp, err := cl.WithAccount(acc).WithAccountName("validator1").WithBroadcastMode(TxBlockMode).Currencies().Issue(issueMsg, "msgID#1")
require.NoError(t, err)
require.True(t, resp.Code == 0)
}