-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathapi_integration_test.go
65 lines (53 loc) · 1.75 KB
/
api_integration_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
//go:build integration
package centchain_test
import (
"context"
"os"
"sync"
"testing"
"github.com/centrifuge/go-centrifuge/bootstrap"
cc "github.com/centrifuge/go-centrifuge/bootstrap/bootstrappers/testingbootstrap"
"github.com/centrifuge/go-centrifuge/centchain"
"github.com/centrifuge/go-centrifuge/config"
"github.com/centrifuge/go-centrifuge/contextutil"
"github.com/centrifuge/go-centrifuge/jobs"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/stretchr/testify/assert"
)
var api centchain.API
var cfg config.Configuration
var cfgSrv config.Service
func TestMain(m *testing.M) {
ctx := cc.TestFunctionalEthereumBootstrap()
api = ctx[centchain.BootstrappedCentChainClient].(centchain.API)
dispatcher := ctx[jobs.BootstrappedDispatcher].(jobs.Dispatcher)
cfg = ctx[bootstrap.BootstrappedConfig].(config.Configuration)
cfgSrv = ctx[config.BootstrappedConfigStorage].(config.Service)
ctxh, canc := context.WithCancel(context.Background())
wg := new(sync.WaitGroup)
wg.Add(1)
go dispatcher.Start(ctxh, wg, nil)
result := m.Run()
cc.TestFunctionalEthereumTearDown()
canc()
wg.Wait()
os.Exit(result)
}
func TestApi_SubmitAndWatch(t *testing.T) {
meta, err := api.GetMetadataLatest()
assert.NoError(t, err)
call, err := types.NewCall(meta, "System.remark", []byte{})
assert.NoError(t, err)
id, err := cfg.GetIdentityID()
assert.NoError(t, err)
acc, err := cfgSrv.GetAccount(id)
assert.NoError(t, err)
caa := acc.GetCentChainAccount()
kr, err := caa.KeyRingPair()
assert.NoError(t, err)
info, err := api.SubmitAndWatch(contextutil.WithAccount(context.Background(), acc), meta, call, kr)
assert.NoError(t, err)
events, err := info.Events(meta)
assert.NoError(t, err)
assert.True(t, len(events.System_ExtrinsicSuccess) > 1)
}