forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bank_test.go
77 lines (60 loc) · 2.6 KB
/
bank_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
package database_test
import (
sdk "github.com/cosmos/cosmos-sdk/types"
dbtypes "github.com/forbole/bdjuno/v2/database/types"
bddbtypes "github.com/forbole/bdjuno/v2/database/types"
)
func (suite *DbTestSuite) TestBigDipperDb_SaveSupply() {
// Save the data
original := sdk.NewCoins(
sdk.NewCoin("desmos", sdk.NewInt(10000)),
sdk.NewCoin("uatom", sdk.NewInt(15)),
)
err := suite.database.SaveSupply(original, 10)
suite.Require().NoError(err)
// Verify the data
expected := bddbtypes.NewSupplyRow(dbtypes.NewDbCoins(original), 10)
var rows []bddbtypes.SupplyRow
err = suite.database.Sqlx.Select(&rows, `SELECT * FROM supply`)
suite.Require().NoError(err)
suite.Require().Len(rows, 1, "supply table should contain only one row")
suite.Require().True(expected.Equals(rows[0]))
// ----------------------------------------------------------------------------------------------------------------
// Try updating with a lower height
coins := sdk.NewCoins(
sdk.NewCoin("desmos", sdk.NewInt(10000)),
sdk.NewCoin("uatom", sdk.NewInt(15)),
)
err = suite.database.SaveSupply(coins, 9)
suite.Require().NoError(err)
// Verify the data
rows = []bddbtypes.SupplyRow{}
err = suite.database.Sqlx.Select(&rows, `SELECT * FROM supply`)
suite.Require().NoError(err)
suite.Require().Len(rows, 1, "supply table should contain only one row")
suite.Require().True(expected.Equals(rows[0]))
// ----------------------------------------------------------------------------------------------------------------
// Try updating with same height
coins = sdk.NewCoins(sdk.NewCoin("uakash", sdk.NewInt(10)))
err = suite.database.SaveSupply(coins, 10)
suite.Require().NoError(err)
// Verify the data
expected = bddbtypes.NewSupplyRow(dbtypes.NewDbCoins(coins), 10)
rows = []bddbtypes.SupplyRow{}
err = suite.database.Sqlx.Select(&rows, `SELECT * FROM supply`)
suite.Require().NoError(err)
suite.Require().Len(rows, 1, "supply table should contain only one row")
suite.Require().True(expected.Equals(rows[0]))
// ----------------------------------------------------------------------------------------------------------------
// Try updating with higher height
coins = sdk.NewCoins(sdk.NewCoin("btc", sdk.NewInt(10)))
err = suite.database.SaveSupply(coins, 20)
suite.Require().NoError(err)
// Verify the data
expected = bddbtypes.NewSupplyRow(dbtypes.NewDbCoins(coins), 20)
rows = []bddbtypes.SupplyRow{}
err = suite.database.Sqlx.Select(&rows, `SELECT * FROM supply`)
suite.Require().NoError(err)
suite.Require().Len(rows, 1, "supply table should contain only one row")
suite.Require().True(expected.Equals(rows[0]))
}