mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
[R4R] fixing dredd tests for bump to v38 of sdk (#464)
* updates, logging, fix key generation using mnemonic etc, still a wip * updates * fix: use test backend for keybase * fix: add keyring flags for all commands * fix: update cdp params to account for breaking changes * fixed issues, all tests now passing * clean up comments Co-authored-by: John Maheswaran <john@noreply> Co-authored-by: Kevin Davis <kjydavis3@gmail.com>
This commit is contained in:
parent
9d98514aaf
commit
56a311dc04
@ -1,11 +1,10 @@
|
||||
#! /bin/bash
|
||||
|
||||
# kill kava if it is already running
|
||||
pgrep kvd | xargs kill
|
||||
pgrep kvcli | xargs kill
|
||||
pkill kvd && pkill kvcli
|
||||
|
||||
# TODO import from development environment in envkey
|
||||
password="password"
|
||||
password=""
|
||||
validatorMnemonic="equip town gesture square tomorrow volume nephew minute witness beef rich gadget actress egg sing secret pole winter alarm law today check violin uncover"
|
||||
# address: kava1ffv7nhd3z6sych2qpqkk03ec6hzkmufy0r2s4c
|
||||
# address: kavavaloper1ffv7nhd3z6sych2qpqkk03ec6hzkmufyz4scd0
|
||||
@ -24,9 +23,10 @@ rm -rf $kvcliHome
|
||||
mkdir /tmp/kvdHome
|
||||
mkdir /tmp/kvcliHome
|
||||
# create validator key
|
||||
printf "$password\n$validatorMnemonic\n" | kvcli keys add vlad --recover --home $kvcliHome
|
||||
printf "$validatorMnemonic\n" | kvcli keys add vlad --recover --home $kvcliHome --keyring-backend test
|
||||
# create faucet key
|
||||
printf "$password\n$faucet\n" | kvcli --home $kvcliHome keys add faucet --recover --home $kvcliHome
|
||||
printf "$faucet\n" | kvcli --home $kvcliHome keys add faucet --recover --home $kvcliHome --keyring-backend test
|
||||
|
||||
# function used to show that it is still loading
|
||||
showLoading() {
|
||||
mypid=$!
|
||||
@ -51,11 +51,11 @@ kvd --home $kvdHome init --chain-id=testing vlad # doesn't need to be the same a
|
||||
} > /dev/null 2>&1
|
||||
kvcli --home $kvcliHome config chain-id testing # or set trust-node true
|
||||
# add validator account to genesis
|
||||
kvd --home $kvdHome add-genesis-account $(kvcli --home $kvcliHome keys show vlad -a) 10000000000000stake,1000000000000xrp,100000000000btc
|
||||
kvd --home $kvdHome add-genesis-account $(kvcli keys show vlad -a --keyring-backend test --home $kvcliHome) 10000000000000stake,1000000000000xrp,100000000000btc
|
||||
# add faucet account to genesis
|
||||
kvd --home $kvdHome add-genesis-account $(kvcli --home $kvcliHome keys show faucet -a) 10000000000000stake,1000000000000xrp,100000000000btc
|
||||
kvd --home $kvdHome add-genesis-account $(kvcli keys show faucet -a --keyring-backend test --home $kvcliHome) 10000000000000stake,1000000000000xrp,100000000000btc
|
||||
# Create a delegation tx for the validator and add to genesis
|
||||
printf "$password\n" | kvd --home $kvdHome gentx --name vlad --home-client $kvcliHome
|
||||
kvd --home $kvdHome gentx --name vlad --home-client $kvcliHome --keyring-backend test
|
||||
{
|
||||
kvd --home $kvdHome collect-gentxs
|
||||
} > /dev/null 2>&1
|
||||
@ -65,7 +65,7 @@ jq '.app_state.mint.params.blocks_per_year = "31540000"' $genesis > $genesis.tmp
|
||||
jq '.app_state.pricefeed.params.markets += [{"active": true, "base_asset": "xrp", "market_id": "xrp:usd", "oracles": ["kava1ffv7nhd3z6sych2qpqkk03ec6hzkmufy0r2s4c"], "quote_asset": "usd"}, {"active": true, "base_asset": "btc", "market_id": "btc:usd", "oracles": ["kava1ffv7nhd3z6sych2qpqkk03ec6hzkmufy0r2s4c"], "quote_asset": "usd"}]' $genesis > $genesis.tmp && mv $genesis.tmp $genesis
|
||||
jq '.app_state.pricefeed.posted_prices += [{"expiry": "2050-01-01T00:00:00Z", "market_id": "btc:usd", "oracle_address": "kava1ffv7nhd3z6sych2qpqkk03ec6hzkmufy0r2s4c", "price": "8700.0"}, {"expiry": "2050-01-01T00:00:00Z", "market_id": "xrp:usd", "oracle_address": "kava1ffv7nhd3z6sych2qpqkk03ec6hzkmufy0r2s4c", "price": "0.25"}]' $genesis > $genesis.tmp && mv $genesis.tmp $genesis
|
||||
# now update cdp params
|
||||
jq '.app_state.cdp.params = { "circuit_breaker": false, "collateral_params": [ { "auction_size": "10000000000", "conversion_factor": "8", "debt_limit": [ { "amount": "1000000000", "denom": "usdx" } ], "denom": "btc", "liquidation_penalty": "0.05", "liquidation_ratio": "1.5", "market_id": "btc:usd", "prefix": 0, "stability_fee": "1.0000000007829977" }, { "auction_size": "100000000", "conversion_factor": "6", "debt_limit": [ { "amount": "10000000", "denom": "usdx" } ], "denom": "xrp", "liquidation_penalty": "0.1", "liquidation_ratio": "2.0", "market_id": "xrp:usd", "prefix": 1, "stability_fee": "1.0000000007829977"} ], "debt_auction_threshold": "9000000", "debt_params": [ { "conversion_factor": "6", "debt_floor": "10000000", "debt_limit": [ { "amount": "2000000000000", "denom": "usdx" } ], "denom": "usdx", "reference_asset": "usd", "savings_rate": "0.95" } ], "global_debt_limit": [ { "amount": "2000000000000", "denom": "usdx" } ], "surplus_auction_threshold": "9000000", "savings_distribution_frequency": "120000000000" }' $genesis > $genesis.tmp && mv $genesis.tmp $genesis
|
||||
jq '.app_state.cdp.params = { "circuit_breaker": false, "collateral_params": [ { "auction_size": "10000000000", "conversion_factor": "8", "debt_limit": { "amount": "1000000000000", "denom": "usdx" }, "denom": "btc", "liquidation_penalty": "0.05", "liquidation_ratio": "1.5", "market_id": "btc:usd", "prefix": 0, "stability_fee": "1.0000000007829977" }, { "auction_size": "100000000", "conversion_factor": "6", "debt_limit": { "amount": "1000000000000", "denom": "usdx" }, "denom": "xrp", "liquidation_penalty": "0.1", "liquidation_ratio": "2.0", "market_id": "xrp:usd", "prefix": 1, "stability_fee": "1.0000000007829977"} ], "debt_auction_threshold": "10000000000", "debt_param": { "conversion_factor": "6", "debt_floor": "10000000", "denom": "usdx", "reference_asset": "usd", "savings_rate": "0.95" }, "global_debt_limit": { "amount": "2000000000000", "denom": "usdx" }, "surplus_auction_threshold": "10000000000", "savings_distribution_frequency": "43200000000000" }' $genesis > $genesis.tmp && mv $genesis.tmp $genesis
|
||||
# start the blockchain in the background, wait until it starts making blocks
|
||||
{
|
||||
kvd start --home $kvdHome & kvdPid="$!"
|
||||
@ -83,7 +83,7 @@ printf "\n"
|
||||
rm -f rest_test/setuptest
|
||||
go build rest_test/setup/setuptest.go & showLoading "Building go test file, please wait"
|
||||
# run the go code to send transactions to the chain and set it up correctly
|
||||
./setuptest $kvcliHome & showLoading "Sending messages to blockchain"
|
||||
./setuptest
|
||||
printf "\n"
|
||||
printf "Blockchain setup completed"
|
||||
printf "\n\n"
|
||||
|
@ -1,19 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkrest "github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
|
||||
authclient "github.com/cosmos/cosmos-sdk/x/auth/client/utils"
|
||||
@ -31,19 +30,19 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
version.Name = "kava"
|
||||
config := sdk.GetConfig()
|
||||
app.SetBech32AddressPrefixes(config)
|
||||
app.SetBip44CoinType(config)
|
||||
config.Seal()
|
||||
keybase = getKeybase()
|
||||
}
|
||||
|
||||
var (
|
||||
keybase crkeys.Keybase
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Printf("Please include the kvcli home directory as a command line argument\n")
|
||||
fmt.Printf("For example: ./setuptest /tmp/kvcliHome\n")
|
||||
fmt.Printf("Exiting...goodbye!\n")
|
||||
return
|
||||
}
|
||||
|
||||
// setup messages send to blockchain so it is in the correct state for testing
|
||||
sendProposal()
|
||||
@ -53,14 +52,6 @@ func main() {
|
||||
sendUndelegation()
|
||||
sendCoins()
|
||||
|
||||
sendProposal()
|
||||
sendDeposit()
|
||||
sendVote()
|
||||
sendDelegation()
|
||||
sendUndelegation()
|
||||
|
||||
sendCoins()
|
||||
|
||||
// create an XRP cdp and send to blockchain
|
||||
sendXrpCdp()
|
||||
|
||||
@ -234,7 +225,7 @@ func sendDeposit() {
|
||||
|
||||
// create a deposit transaction to send to the proposal
|
||||
amount := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 10000000))
|
||||
deposit := gov.NewMsgDeposit(addr, 2, amount) // TODO IMPORTANT '2' must match 'x-example' in swagger.yaml
|
||||
deposit := gov.NewMsgDeposit(addr, 1, amount) // Note: '1' must match 'x-example' in swagger.yaml
|
||||
depositToSend := []sdk.Msg{deposit}
|
||||
|
||||
sendMsgToBlockchain(cdc, address, keyname, password, depositToSend, keybase)
|
||||
@ -261,7 +252,7 @@ func sendVote() {
|
||||
// NOW SEND THE VOTE
|
||||
|
||||
// create a vote on a proposal to send to the blockchain
|
||||
vote := gov.NewMsgVote(addr, uint64(2), types.OptionYes) // TODO IMPORTANT '2' must match 'x-example' in swagger.yaml
|
||||
vote := gov.NewMsgVote(addr, uint64(1), types.OptionYes) // Note: '1' must match 'x-example' in swagger.yaml
|
||||
|
||||
// send a vote to the blockchain
|
||||
voteToSend := []sdk.Msg{vote}
|
||||
@ -281,7 +272,7 @@ func sendCoins() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
addrTo, err := sdk.AccAddressFromBech32("kava1ls82zzghsx0exkpr52m8vht5jqs3un0ceysshz") // TODO IMPORTANT this is the faucet address
|
||||
addrTo, err := sdk.AccAddressFromBech32("kava1ls82zzghsx0exkpr52m8vht5jqs3un0ceysshz") // Note: must match the faucet address
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -295,7 +286,7 @@ func sendCoins() {
|
||||
// create coins
|
||||
amount := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 2000000))
|
||||
|
||||
coins := bank.NewMsgSend(addrFrom, addrTo, amount) // TODO IMPORTANT '2' must match 'x-example' in swagger.yaml
|
||||
coins := bank.NewMsgSend(addrFrom, addrTo, amount) // Note: '1' must match 'x-example' in swagger.yaml
|
||||
coinsToSend := []sdk.Msg{coins}
|
||||
|
||||
// NOW SEND THE COINS
|
||||
@ -306,14 +297,14 @@ func sendCoins() {
|
||||
}
|
||||
|
||||
func getTestAddress() (address string) {
|
||||
// the test address - TODO IMPORTANT make sure this lines up with startchain.sh
|
||||
// the test address - Note: this must match with startchain.sh
|
||||
address = "kava1ffv7nhd3z6sych2qpqkk03ec6hzkmufy0r2s4c"
|
||||
return address
|
||||
}
|
||||
|
||||
func getKeynameAndPassword() (keyname string, password string) {
|
||||
keyname = "vlad" // TODO - IMPORTANT this must match the keys in the startchain.sh script
|
||||
password = "password" // TODO - IMPORTANT this must match the keys in the startchain.sh script
|
||||
keyname = "vlad" // Note: this must match the keys in the startchain.sh script
|
||||
password = "" // Note: this must match the keys in the startchain.sh script
|
||||
return keyname, password
|
||||
}
|
||||
|
||||
@ -385,13 +376,22 @@ func sendUndelegation() {
|
||||
}
|
||||
|
||||
func getKeybase() crkeys.Keybase {
|
||||
|
||||
if keybase != nil {
|
||||
return keybase
|
||||
}
|
||||
|
||||
// create a keybase
|
||||
// IMPORTANT - TAKE THIS FROM COMMAND LINE PARAMETER and does NOT work with tilde i.e. ~/ does NOT work
|
||||
keybase, err := keys.NewKeyBaseFromDir(os.Args[1])
|
||||
// myKeybase, err := keys.NewKeyBaseFromDir("/tmp/kvcliHome")
|
||||
|
||||
inBuf := strings.NewReader("")
|
||||
keybase, err := crkeys.NewKeyring(sdk.KeyringServiceName(),
|
||||
"test", "/tmp/kvcliHome", inBuf)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return keybase
|
||||
}
|
||||
|
||||
@ -401,16 +401,17 @@ func sendMsgToBlockchain(cdc *codec.Codec, address string, keyname string,
|
||||
|
||||
// get the account number and sequence number
|
||||
accountNumber, sequenceNumber := getAccountNumberAndSequenceNumber(cdc, address)
|
||||
inBuf := bufio.NewReader(os.Stdin)
|
||||
txBldr := auth.NewTxBuilderFromCLI(inBuf).
|
||||
WithTxEncoder(authclient.GetTxEncoder(cdc)).WithChainID("testing").
|
||||
|
||||
txBldr := auth.NewTxBuilder(
|
||||
authclient.GetTxEncoder(cdc), accountNumber, sequenceNumber, 500000, 0,
|
||||
true, "testing", "memo", sdk.NewCoins(), sdk.NewDecCoins(),
|
||||
).WithTxEncoder(authclient.GetTxEncoder(cdc)).WithChainID("testing").
|
||||
WithKeybase(keybase).WithAccountNumber(accountNumber).
|
||||
WithSequence(sequenceNumber).WithGas(500000)
|
||||
|
||||
// build and sign the transaction
|
||||
// this is the *Amino* encoded version of the transaction
|
||||
// fmt.Printf("%+v", txBldr.Keybase())
|
||||
txBytes, err := txBldr.BuildAndSign("vlad", "password", msg)
|
||||
txBytes, err := txBldr.BuildAndSign("vlad", "", msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -433,7 +434,9 @@ func sendMsgToBlockchain(cdc *codec.Codec, address string, keyname string,
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// fmt.Println("post body: ", string(jsonBytes))
|
||||
fmt.Println()
|
||||
fmt.Println("post body: ", string(jsonBytes))
|
||||
fmt.Println()
|
||||
|
||||
resp, err := http.Post("http://localhost:1317/txs", "application/json", bytes.NewBuffer(jsonBytes))
|
||||
if err != nil {
|
||||
|
@ -237,7 +237,7 @@
|
||||
description: Tx hash
|
||||
required: true
|
||||
type: string
|
||||
x-example: 4B2C3449FF2647BD51B54C32761FE4EBE7AE024BBE2A9898972A69BEB82D97C2
|
||||
x-example: FFC8D0E5D52D330AD315E950E5C18A9D65FC640156B9A95B5AEF07DDAE32E61D
|
||||
responses:
|
||||
200:
|
||||
description: Tx with the provided hash
|
||||
@ -400,13 +400,9 @@
|
||||
owner:
|
||||
$ref: '#/definitions/Address'
|
||||
collateral:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/CoinCollateral'
|
||||
$ref: '#/definitions/CoinCollateral'
|
||||
principal:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/CoinPrincipal'
|
||||
$ref: '#/definitions/CoinPrincipal'
|
||||
responses:
|
||||
200:
|
||||
description: Tx was successfully generated
|
||||
@ -450,9 +446,7 @@
|
||||
depositor:
|
||||
$ref: '#/definitions/Address'
|
||||
collateral:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/CoinCollateral'
|
||||
$ref: '#/definitions/CoinCollateral'
|
||||
responses:
|
||||
200:
|
||||
description: Tx was successfully generated
|
||||
@ -496,9 +490,7 @@
|
||||
depositor:
|
||||
$ref: '#/definitions/Address'
|
||||
collateral:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/CoinCollateral'
|
||||
$ref: '#/definitions/CoinCollateral'
|
||||
responses:
|
||||
200:
|
||||
description: Tx was successfully generated
|
||||
@ -540,9 +532,7 @@
|
||||
owner:
|
||||
$ref: '#/definitions/Address'
|
||||
principal:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/CoinPrincipal'
|
||||
$ref: '#/definitions/CoinPrincipal'
|
||||
responses:
|
||||
200:
|
||||
description: Tx was successfully generated
|
||||
@ -584,9 +574,7 @@
|
||||
owner:
|
||||
$ref: '#/definitions/Address'
|
||||
payment:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/CoinPrincipal'
|
||||
$ref: '#/definitions/CoinPrincipal'
|
||||
responses:
|
||||
200:
|
||||
description: Tx was successfully generated
|
||||
@ -725,7 +713,7 @@
|
||||
description: Server internal error
|
||||
/cdp/cdps/cdp/deposits/{owner}/{denom}:
|
||||
get:
|
||||
summary: Get the deposits associated with the cdp owned by the input owner address and with colalteral type equal to the input collateral denom
|
||||
summary: Get the deposits associated with the cdp owned by the input owner address and with collateral type equal to the input collateral denom
|
||||
tags:
|
||||
- CDP
|
||||
produces:
|
||||
@ -1888,7 +1876,7 @@
|
||||
name: proposalId
|
||||
required: true
|
||||
in: path
|
||||
x-example: '2'
|
||||
x-example: '1'
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
@ -1911,7 +1899,7 @@
|
||||
name: proposalId
|
||||
required: true
|
||||
in: path
|
||||
x-example: '2'
|
||||
x-example: '1'
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
@ -1934,7 +1922,7 @@
|
||||
name: proposalId
|
||||
required: true
|
||||
in: path
|
||||
x-example: '2'
|
||||
x-example: '1'
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
@ -1966,7 +1954,7 @@
|
||||
name: proposalId
|
||||
required: true
|
||||
in: path
|
||||
x-example: '2'
|
||||
x-example: '1'
|
||||
- description: ''
|
||||
name: post_deposit_body
|
||||
in: body
|
||||
@ -2007,7 +1995,7 @@
|
||||
name: proposalId
|
||||
required: true
|
||||
in: path
|
||||
x-example: "2"
|
||||
x-example: "1"
|
||||
- type: string
|
||||
description: Bech32 depositor address
|
||||
name: depositor
|
||||
@ -2039,7 +2027,7 @@
|
||||
name: proposalId
|
||||
required: true
|
||||
in: path
|
||||
x-example: '2'
|
||||
x-example: '1'
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
@ -2071,7 +2059,7 @@
|
||||
name: proposalId
|
||||
required: true
|
||||
in: path
|
||||
x-example: '2'
|
||||
x-example: '1'
|
||||
- description: valid value of `"option"` field can be `"yes"`, `"no"`, `"no_with_veto"` and `"abstain"`
|
||||
name: post_vote_body
|
||||
in: body
|
||||
@ -2111,7 +2099,7 @@
|
||||
name: proposalId
|
||||
required: true
|
||||
in: path
|
||||
x-example: '2'
|
||||
x-example: '1'
|
||||
- type: string
|
||||
description: Bech32 voter address
|
||||
name: voter
|
||||
@ -2143,7 +2131,7 @@
|
||||
name: proposalId
|
||||
required: true
|
||||
in: path
|
||||
x-example: '2'
|
||||
x-example: '1'
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
@ -3098,9 +3086,7 @@
|
||||
type: string
|
||||
example: kava1q53rwutgpzx7szcrgzqguxyccjpzt9j4cyctn9
|
||||
amount:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/CoinCollateral'
|
||||
$ref: '#/definitions/CoinCollateral'
|
||||
PricefeedParameters:
|
||||
type: object
|
||||
properties:
|
||||
|
Loading…
Reference in New Issue
Block a user