forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See PR forbole#67
- Loading branch information
Showing
76 changed files
with
877 additions
and
1,524 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,16 +23,6 @@ jobs: | |
- uses: actions/checkout@v2 | ||
- name: Test & Coverage report creation | ||
run: make install test-unit stop-docker-test | ||
- name: Filter out DONTCOVER | ||
run: | | ||
excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')" | ||
excludelist+=" $(find ./ -type f -name '*.pb.go')" | ||
excludelist+=" $(find ./ -type f -path './tests/mocks/*.go')" | ||
for filename in ${excludelist}; do | ||
filename=$(echo $filename | sed 's/^./github.com\/forbole\/bdjuno/g') | ||
echo "Excluding ${filename} from coverage report..." | ||
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt | ||
done | ||
- uses: codecov/[email protected] | ||
with: | ||
file: ./coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package database | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/lib/pq" | ||
|
||
dbtypes "github.com/forbole/bdjuno/database/types" | ||
) | ||
|
||
// SaveAccountBalance allows to store the balance for the given account associating it to the given height | ||
func (db *BigDipperDb) SaveAccountBalance(address string, balance sdk.Coins, height int64) error { | ||
coins := pq.Array(dbtypes.NewDbCoins(balance)) | ||
|
||
stmt := ` | ||
INSERT INTO account_balance (address, coins) | ||
VALUES ($1, $2) ON CONFLICT (address) DO UPDATE | ||
SET coins = excluded.coins` | ||
_, err := db.Sql.Exec(stmt, address, coins) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
stmt = `INSERT INTO account_balance_history (address, coins, height) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING` | ||
_, err = db.Sql.Exec(stmt, address, coins, height) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package database_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
dbtypes "github.com/forbole/bdjuno/database/types" | ||
) | ||
|
||
func (suite *DbTestSuite) TestSaveAccountBalance() { | ||
address := suite.getAccount("cosmos140xsjjg6pwkjp0xjz8zru7ytha60l5aee9nlf7") | ||
height := int64(100) | ||
coins := sdk.NewCoins( | ||
sdk.NewCoin("desmos", sdk.NewInt(10000)), | ||
sdk.NewCoin("uatom", sdk.NewInt(15)), | ||
) | ||
|
||
// Save the balance | ||
err := suite.database.SaveAccountBalance(address.String(), coins, height) | ||
suite.Require().NoError(err) | ||
|
||
// Current balances | ||
var balRows []dbtypes.AccountBalanceRow | ||
err = suite.database.Sqlx.Select(&balRows, `SELECT * FROM account_balance ORDER BY address`) | ||
suite.Require().NoError(err) | ||
suite.Require().Len(balRows, 1) | ||
suite.Require().True(balRows[0].Equal(dbtypes.NewAccountBalanceRow( | ||
"cosmos140xsjjg6pwkjp0xjz8zru7ytha60l5aee9nlf7", | ||
dbtypes.NewDbCoins(coins), | ||
))) | ||
|
||
// Balance histories | ||
var balHisRows []dbtypes.AccountBalanceHistoryRow | ||
err = suite.database.Sqlx.Select(&balHisRows, `SELECT * FROM account_balance_history ORDER BY address`) | ||
suite.Require().NoError(err) | ||
suite.Require().Len(balHisRows, 1) | ||
suite.Require().True(balHisRows[0].Equal(dbtypes.NewAccountBalanceHistoryRow( | ||
"cosmos140xsjjg6pwkjp0xjz8zru7ytha60l5aee9nlf7", | ||
dbtypes.NewDbCoins(coins), | ||
height, | ||
))) | ||
} |
Oops, something went wrong.