-
Notifications
You must be signed in to change notification settings - Fork 17
/
bdd_test.go
98 lines (76 loc) · 2.16 KB
/
bdd_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
94
95
96
97
98
//go:build bdd
package emoney_test
import (
"encoding/json"
"testing"
"time"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
. "github.com/onsi/gomega"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
nt "github.com/e-money/em-ledger/networktest"
apptypes "github.com/e-money/em-ledger/types"
"github.com/e-money/em-ledger/x/inflation"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
)
var (
testnet = func() nt.Testnet {
version.Name = "e-money" // Used by the keyring library.
version.AppName = "emd"
apptypes.ConfigureSDK()
return nt.NewTestnet()
}()
// If set to false, the tests will not clean up the docker containers that are started during the tests.
tearDownAfterTests = true
)
func createNewTestnet() {
awaitReady, err := testnet.Restart()
Expect(err).ShouldNot(HaveOccurred())
Expect(awaitReady()).To(BeTrue())
}
func TestSuite(t *testing.T) {
BeforeSuite(func() {
err := testnet.Setup()
Expect(err).ShouldNot(HaveOccurred())
})
AfterSuite(func() {
if tearDownAfterTests {
err := testnet.Teardown()
Expect(err).ShouldNot(HaveOccurred())
}
})
RegisterFailHandler(Fail)
config.DefaultReporterConfig.SlowSpecThreshold = time.Hour.Seconds()
RunSpecs(t, "em-ledger integration tests")
}
func setGenesisTime(genesis []byte, genesisTime time.Time) []byte {
bz, err := sjson.SetBytes(genesis, "genesis_time", genesisTime.Format(time.RFC3339))
if err != nil {
panic(err)
}
return bz
}
func setInflation(genesis []byte, denom string, newInflation sdk.Dec) []byte {
inflationJsonGen := gjson.GetBytes(genesis, "app_state.inflation")
inflationGen := new(inflation.GenesisState)
err := json.Unmarshal([]byte(inflationJsonGen.String()), inflationGen)
if err != nil {
panic(err)
}
for index, asset := range inflationGen.InflationState.InflationAssets {
if asset.Denom == denom {
inflationGen.InflationState.InflationAssets[index].Inflation = newInflation
}
}
updatedInflation, err := json.Marshal(inflationGen)
if err != nil {
panic(err)
}
bz, err := sjson.SetRawBytes(genesis, "app_state.inflation", updatedInflation)
if err != nil {
panic(err)
}
return bz
}