mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-24 15:25:18 +00:00
Merge branch 'master' of github.com:Kava-Labs/kava into sim-store-decoder
This commit is contained in:
commit
f827d896ba
@ -21,7 +21,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
Reference implementation of Kava, a blockchain for cross-chain DeFi. Built using the [comsos-sdk](https://github.com/cosmos/cosmos-sdk).
|
||||
Reference implementation of Kava, a blockchain for cross-chain DeFi. Built using the [cosmos-sdk](https://github.com/cosmos/cosmos-sdk).
|
||||
|
||||
## Mainnet
|
||||
|
||||
|
@ -60,3 +60,11 @@ Congratulations, you've just posted a current market price on Kava using the res
|
||||
## Governance proposals
|
||||
|
||||
Example governance proposals are located in `/proposal_examples`.
|
||||
|
||||
## Dredd automated REST API testing
|
||||
|
||||
To run the dredd tests to hit the endpoints and test the api run the following command from the `kava` folder:
|
||||
|
||||
```bash
|
||||
make test_dredd
|
||||
```
|
@ -1,40 +1,37 @@
|
||||
#! /bin/bash
|
||||
|
||||
# kill kava if it is already running
|
||||
pgrep kvd | xargs kill
|
||||
pgrep kvcli | xargs kill
|
||||
|
||||
# TODO import from development environment in envkey
|
||||
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
|
||||
|
||||
faucet="chief access utility giant burger winner jar false naive mobile often perfect advice village love enroll embark bacon under flock harbor render father since"
|
||||
|
||||
# address: kava1ls82zzghsx0exkpr52m8vht5jqs3un0ceysshz
|
||||
# address: kavavaloper1ls82zzghsx0exkpr52m8vht5jqs3un0c5j2c04
|
||||
|
||||
# variables for home directories for kvd and kvcli
|
||||
kvdHome=/tmp/kvdHome
|
||||
kvcliHome=/tmp/kvcliHome
|
||||
|
||||
genesis=$kvdHome/config/genesis.json
|
||||
swaggerFile=swagger-ui/testnet-4000/swagger-testnet-4000.yaml
|
||||
# Remove any existing data directory
|
||||
rm -rf $kvdHome
|
||||
rm -rf $kvcliHome
|
||||
|
||||
# make the directories
|
||||
mkdir /tmp/kvdHome
|
||||
mkdir /tmp/kvcliHome
|
||||
|
||||
# create validator key
|
||||
printf "$password\n$validatorMnemonic\n" | kvcli keys add vlad --recover --home $kvcliHome
|
||||
# create faucet key
|
||||
printf "$password\n$faucet\n" | kvcli --home $kvcliHome keys add faucet --recover --home $kvcliHome
|
||||
|
||||
# function used to show that it is still loading
|
||||
showLoading() {
|
||||
mypid=$!
|
||||
loadingText=$1
|
||||
|
||||
echo -ne "$loadingText\r"
|
||||
|
||||
while kill -0 $mypid 2>/dev/null; do
|
||||
echo -ne "$loadingText.\r"
|
||||
sleep 0.5
|
||||
@ -46,32 +43,33 @@ showLoading() {
|
||||
echo -ne "$loadingText\r"
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
echo "$loadingText...finished"
|
||||
}
|
||||
|
||||
# Create new data directory
|
||||
{
|
||||
kvd --home $kvdHome init --chain-id=testing vlad # doesn't need to be the same as the validator
|
||||
} > /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
|
||||
kvd --home $kvdHome add-genesis-account $(kvcli --home $kvcliHome keys show vlad -a) 10000000000000stake,1000000000000xrp,100000000000btc
|
||||
# add faucet account to genesis
|
||||
kvd --home $kvdHome add-genesis-account $(kvcli --home $kvcliHome keys show faucet -a) 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 collect-gentxs
|
||||
} > /dev/null 2>&1
|
||||
|
||||
# set blocktime to ~1s
|
||||
jq '.app_state.mint.params.blocks_per_year = "31540000"' $genesis > $genesis.tmp && mv $genesis.tmp $genesis
|
||||
# update pricefeed information
|
||||
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
|
||||
# start the blockchain in the background, wait until it starts making blocks
|
||||
{
|
||||
kvd start --home $kvdHome & kvdPid="$!"
|
||||
} > /dev/null 2>&1
|
||||
|
||||
printf "\n"
|
||||
sleep 10 & showLoading "Starting rest server, please wait"
|
||||
# start the rest server. Use ./stopchain.sh to stop both rest server and the blockchain
|
||||
@ -81,28 +79,22 @@ kvcli rest-server --laddr tcp://127.0.0.1:1317 --chain-id=testing --home $kvcliH
|
||||
printf "\n"
|
||||
sleep 10 & showLoading "Preparing blockchain setup transactions, please wait"
|
||||
printf "\n"
|
||||
|
||||
# build the go setup test file
|
||||
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"
|
||||
printf "\n"
|
||||
printf "Blockchain setup completed"
|
||||
printf "\n\n"
|
||||
|
||||
############################
|
||||
# Now run the dredd tests
|
||||
############################
|
||||
|
||||
dredd swagger-ui/swagger.yaml localhost:1317 2>&1 | tee output & showLoading "Running dredd tests"
|
||||
|
||||
dredd $swaggerFile localhost:1317 2>&1 | tee output & showLoading "Running dredd tests"
|
||||
########################################################
|
||||
# Now run the check the return code from the dredd command.
|
||||
# If 0 then all test passed OK, otherwise some failed and propagate the error
|
||||
########################################################
|
||||
|
||||
# check that the error code was zero
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
@ -122,7 +114,6 @@ then
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# otherwise return an error code and redirect stderr to stdout so user sees the error output
|
||||
echo "Failure" >&2
|
||||
rm setuptest & showLoading "Cleaning up go binary"
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
@ -20,7 +21,10 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/x/cdp"
|
||||
"github.com/kava-labs/kava/x/pricefeed"
|
||||
"github.com/tendermint/go-amino"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -31,6 +35,14 @@ func init() {
|
||||
}
|
||||
|
||||
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()
|
||||
sendDeposit()
|
||||
sendVote()
|
||||
@ -46,6 +58,122 @@ func main() {
|
||||
|
||||
sendCoins()
|
||||
|
||||
// create an XRP cdp and send to blockchain
|
||||
sendXrpCdp()
|
||||
|
||||
// create a BTC cdp and send to blockchain
|
||||
sendBtcCdp()
|
||||
|
||||
// reduce the price of BTC to trigger an auction
|
||||
sendMsgPostPrice()
|
||||
}
|
||||
|
||||
// lower the price of xrp to trigger an auction
|
||||
func sendMsgPostPrice() {
|
||||
// get the address
|
||||
address := getTestAddress()
|
||||
// get the keyname and password
|
||||
keyname, password := getKeynameAndPassword()
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(address) // validator address
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
price, err := sdk.NewDecFromStr("1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// set the expiry time
|
||||
expiry := tmtime.Now().Add(time.Second * 100000)
|
||||
|
||||
// create a cdp message to send to the blockchain
|
||||
// from, assetcode, price, expiry
|
||||
msg := pricefeed.NewMsgPostPrice(
|
||||
addr,
|
||||
"btc:usd",
|
||||
price,
|
||||
expiry,
|
||||
)
|
||||
|
||||
// helper methods for transactions
|
||||
cdc := app.MakeCodec() // make codec for the app
|
||||
|
||||
// get the keybase
|
||||
keybase := getKeybase()
|
||||
|
||||
// cast to the generic msg type
|
||||
msgToSend := []sdk.Msg{msg}
|
||||
|
||||
// send the message to the blockchain
|
||||
sendMsgToBlockchain(cdc, address, keyname, password, msgToSend, keybase)
|
||||
|
||||
}
|
||||
|
||||
func sendBtcCdp() {
|
||||
// get the address
|
||||
address := getTestAddress()
|
||||
// get the keyname and password
|
||||
keyname, password := getKeynameAndPassword()
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(address) // validator address
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// create a cdp message to send to the blockchain
|
||||
// sender, collateral, principal
|
||||
msg := cdp.NewMsgCreateCDP(
|
||||
addr,
|
||||
sdk.NewCoins(sdk.NewInt64Coin("btc", 200000000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("usdx", 10000000)),
|
||||
)
|
||||
|
||||
// helper methods for transactions
|
||||
cdc := app.MakeCodec() // make codec for the app
|
||||
|
||||
// get the keybase
|
||||
keybase := getKeybase()
|
||||
|
||||
// cast to the generic msg type
|
||||
msgToSend := []sdk.Msg{msg}
|
||||
|
||||
// send the message to the blockchain
|
||||
sendMsgToBlockchain(cdc, address, keyname, password, msgToSend, keybase)
|
||||
|
||||
}
|
||||
|
||||
func sendXrpCdp() {
|
||||
// get the address
|
||||
address := getTestAddress()
|
||||
// get the keyname and password
|
||||
keyname, password := getKeynameAndPassword()
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(address) // validator address
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// create a cdp message to send to the blockchain
|
||||
// sender, collateral, principal
|
||||
msg := cdp.NewMsgCreateCDP(
|
||||
addr,
|
||||
sdk.NewCoins(sdk.NewInt64Coin("xrp", 200000000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("usdx", 10000000)),
|
||||
)
|
||||
|
||||
// helper methods for transactions
|
||||
cdc := app.MakeCodec() // make codec for the app
|
||||
|
||||
// get the keybase
|
||||
keybase := getKeybase()
|
||||
|
||||
// cast to the generic msg type
|
||||
msgToSend := []sdk.Msg{msg}
|
||||
|
||||
// send the message to the blockchain
|
||||
sendMsgToBlockchain(cdc, address, keyname, password, msgToSend, keybase)
|
||||
|
||||
}
|
||||
|
||||
func sendProposal() {
|
||||
@ -274,7 +402,7 @@ func sendMsgToBlockchain(cdc *amino.Codec, address string, keyname string,
|
||||
txBldr := auth.NewTxBuilderFromCLI().
|
||||
WithTxEncoder(authclient.GetTxEncoder(cdc)).WithChainID("testing").
|
||||
WithKeybase(keybase).WithAccountNumber(accountNumber).
|
||||
WithSequence(sequenceNumber)
|
||||
WithSequence(sequenceNumber).WithGas(500000)
|
||||
|
||||
// build and sign the transaction
|
||||
// this is the *Amino* encoded version of the transaction
|
||||
@ -296,6 +424,9 @@ func sendMsgToBlockchain(cdc *amino.Codec, address string, keyname string,
|
||||
Mode: "block",
|
||||
},
|
||||
)
|
||||
|
||||
fmt.Printf("%s", bytes.NewBuffer(jsonBytes))
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,7 @@ import (
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/keeper"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/keeper"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/keeper"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/keeper"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
func TestBeginBlockerZeroHeight(t *testing.T) {
|
||||
|
@ -1,13 +1,13 @@
|
||||
// nolint
|
||||
// autogenerated code using github.com/rigelrozanski/multitool
|
||||
// aliases generated for the following subdirectories:
|
||||
// ALIASGEN: github.com/kava-labs/kava/x/validator-vesting/internal/keeper
|
||||
// ALIASGEN: github.com/kava-labs/kava/x/validator-vesting/internal/types
|
||||
// ALIASGEN: github.com/kava-labs/kava/x/validator-vesting/keeper
|
||||
// ALIASGEN: github.com/kava-labs/kava/x/validator-vesting/types
|
||||
package validatorvesting
|
||||
|
||||
import (
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/keeper"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/keeper"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -3,7 +3,7 @@ package cli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
// define routes that get registered by the main application
|
||||
|
@ -2,7 +2,7 @@ package validatorvesting
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
// InitGenesis stores the account address of each ValidatorVestingAccount in the validator vesting keeper, for faster lookup.
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
)
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
func TestGetSetValidatorVestingAccounts(t *testing.T) {
|
@ -4,7 +4,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/x/supply"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
//nolint: deadcode unused
|
@ -15,8 +15,8 @@ import (
|
||||
sim "github.com/cosmos/cosmos-sdk/x/simulation"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/client/cli"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/client/rest"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/simulation"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/exported"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
// DecodeStore unmarshals the KVPair's Value to the corresponding auth type
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
|
||||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/simulation"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
// RandomizedGenState generates a random GenesisState for validator-vesting
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/x/supply"
|
||||
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/keeper"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/keeper"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
var (
|
||||
|
Loading…
Reference in New Issue
Block a user