test deposit values
This commit is contained in:
parent
b1109180ca
commit
2b701655d9
|
@ -10,19 +10,19 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
cryptoKeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
cryptoKeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||||
p2p "github.com/tendermint/tendermint/p2p"
|
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
|
|
||||||
client "github.com/cosmos/cosmos-sdk/client"
|
client "github.com/cosmos/cosmos-sdk/client"
|
||||||
keys "github.com/cosmos/cosmos-sdk/client/keys"
|
keys "github.com/cosmos/cosmos-sdk/client/keys"
|
||||||
rpc "github.com/cosmos/cosmos-sdk/client/rpc"
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
tests "github.com/cosmos/cosmos-sdk/tests"
|
tests "github.com/cosmos/cosmos-sdk/tests"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
@ -613,7 +613,7 @@ func TestSubmitProposal(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
// create SubmitProposal TX
|
// create SubmitProposal TX
|
||||||
resultTx := doSubmitProposal(t, port, seed, name, password, addr)
|
resultTx := doSubmitProposal(t, port, seed, name, password, addr, 5)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
// check if tx was committed
|
// check if tx was committed
|
||||||
|
@ -635,7 +635,7 @@ func TestDeposit(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
// create SubmitProposal TX
|
// create SubmitProposal TX
|
||||||
resultTx := doSubmitProposal(t, port, seed, name, password, addr)
|
resultTx := doSubmitProposal(t, port, seed, name, password, addr, 5)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
// check if tx was committed
|
// check if tx was committed
|
||||||
|
@ -650,7 +650,7 @@ func TestDeposit(t *testing.T) {
|
||||||
require.Equal(t, "Test", proposal.GetTitle())
|
require.Equal(t, "Test", proposal.GetTitle())
|
||||||
|
|
||||||
// create SubmitProposal TX
|
// create SubmitProposal TX
|
||||||
resultTx = doDeposit(t, port, seed, name, password, addr, proposalID)
|
resultTx = doDeposit(t, port, seed, name, password, addr, proposalID, 5)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
// query proposal
|
// query proposal
|
||||||
|
@ -669,7 +669,7 @@ func TestVote(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
// create SubmitProposal TX
|
// create SubmitProposal TX
|
||||||
resultTx := doSubmitProposal(t, port, seed, name, password, addr)
|
resultTx := doSubmitProposal(t, port, seed, name, password, addr, 5)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
// check if tx was committed
|
// check if tx was committed
|
||||||
|
@ -684,7 +684,7 @@ func TestVote(t *testing.T) {
|
||||||
require.Equal(t, "Test", proposal.GetTitle())
|
require.Equal(t, "Test", proposal.GetTitle())
|
||||||
|
|
||||||
// create SubmitProposal TX
|
// create SubmitProposal TX
|
||||||
resultTx = doDeposit(t, port, seed, name, password, addr, proposalID)
|
resultTx = doDeposit(t, port, seed, name, password, addr, proposalID, 5)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
// query proposal
|
// query proposal
|
||||||
|
@ -725,35 +725,51 @@ func TestProposalsQuery(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
// Addr1 proposes (and deposits) proposals #1 and #2
|
// Addr1 proposes (and deposits) proposals #1 and #2
|
||||||
resultTx := doSubmitProposal(t, port, seed, name, password1, addr)
|
resultTx := doSubmitProposal(t, port, seed, name, password1, addr, 5)
|
||||||
var proposalID1 int64
|
var proposalID1 int64
|
||||||
cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID1)
|
cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID1)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
resultTx = doSubmitProposal(t, port, seed, name, password1, addr)
|
resultTx = doSubmitProposal(t, port, seed, name, password1, addr, 5)
|
||||||
var proposalID2 int64
|
var proposalID2 int64
|
||||||
cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID2)
|
cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID2)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
// Addr2 proposes (and deposits) proposals #3
|
// Addr2 proposes (and deposits) proposals #3
|
||||||
resultTx = doSubmitProposal(t, port, seed2, name2, password2, addr2)
|
resultTx = doSubmitProposal(t, port, seed2, name2, password2, addr2, 5)
|
||||||
var proposalID3 int64
|
var proposalID3 int64
|
||||||
cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID3)
|
cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID3)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
// Addr2 deposits on proposals #2 & #3
|
// Addr2 deposits on proposals #2 & #3
|
||||||
resultTx = doDeposit(t, port, seed2, name2, password2, addr2, proposalID2)
|
resultTx = doDeposit(t, port, seed2, name2, password2, addr2, proposalID2, 5)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
resultTx = doDeposit(t, port, seed2, name2, password2, addr2, proposalID3)
|
resultTx = doDeposit(t, port, seed2, name2, password2, addr2, proposalID3, 5)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
|
// check deposits match proposal and individual deposits
|
||||||
deposits := getDeposits(t, port, proposalID1)
|
deposits := getDeposits(t, port, proposalID1)
|
||||||
require.Len(t, deposits, 1)
|
require.Len(t, deposits, 1)
|
||||||
|
deposit := getDeposit(t, port, proposalID1, addr)
|
||||||
|
require.Equal(t, deposit, deposits[0])
|
||||||
|
|
||||||
deposits = getDeposits(t, port, proposalID2)
|
deposits = getDeposits(t, port, proposalID2)
|
||||||
require.Len(t, deposits, 2)
|
require.Len(t, deposits, 2)
|
||||||
|
deposit = getDeposit(t, port, proposalID2, addr)
|
||||||
|
require.Equal(t, deposit, deposits[0])
|
||||||
|
deposit = getDeposit(t, port, proposalID2, addr2)
|
||||||
|
require.Equal(t, deposit, deposits[1])
|
||||||
|
|
||||||
deposits = getDeposits(t, port, proposalID3)
|
deposits = getDeposits(t, port, proposalID3)
|
||||||
require.Len(t, deposits, 1)
|
require.Len(t, deposits, 1)
|
||||||
|
deposit = getDeposit(t, port, proposalID3, addr2)
|
||||||
|
require.Equal(t, deposit, deposits[0])
|
||||||
|
|
||||||
|
// increasing the amount of the deposit should update the existing one
|
||||||
|
resultTx = doDeposit(t, port, seed, name, password1, addr, proposalID1, 1)
|
||||||
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
|
deposits = getDeposits(t, port, proposalID1)
|
||||||
|
require.Len(t, deposits, 1)
|
||||||
|
|
||||||
// Only proposals #1 should be in Deposit Period
|
// Only proposals #1 should be in Deposit Period
|
||||||
proposals := getProposalsFilterStatus(t, port, gov.StatusDepositPeriod)
|
proposals := getProposalsFilterStatus(t, port, gov.StatusDepositPeriod)
|
||||||
|
@ -1263,7 +1279,7 @@ func getProposalsFilterStatus(t *testing.T, port string, status gov.ProposalStat
|
||||||
return proposals
|
return proposals
|
||||||
}
|
}
|
||||||
|
|
||||||
func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress) (resultTx ctypes.ResultBroadcastTxCommit) {
|
func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, amount int64) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||||
|
|
||||||
acc := getAccount(t, port, proposerAddr)
|
acc := getAccount(t, port, proposerAddr)
|
||||||
accnum := acc.GetAccountNumber()
|
accnum := acc.GetAccountNumber()
|
||||||
|
@ -1277,7 +1293,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
|
||||||
"description": "test",
|
"description": "test",
|
||||||
"proposal_type": "Text",
|
"proposal_type": "Text",
|
||||||
"proposer": "%s",
|
"proposer": "%s",
|
||||||
"initial_deposit": [{ "denom": "steak", "amount": "5" }],
|
"initial_deposit": [{ "denom": "steak", "amount": "%d" }],
|
||||||
"base_req": {
|
"base_req": {
|
||||||
"name": "%s",
|
"name": "%s",
|
||||||
"password": "%s",
|
"password": "%s",
|
||||||
|
@ -1285,7 +1301,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
|
||||||
"account_number":"%d",
|
"account_number":"%d",
|
||||||
"sequence":"%d"
|
"sequence":"%d"
|
||||||
}
|
}
|
||||||
}`, proposerAddr, name, password, chainID, accnum, sequence))
|
}`, proposerAddr, amount, name, password, chainID, accnum, sequence))
|
||||||
res, body := Request(t, port, "POST", "/gov/proposals", jsonStr)
|
res, body := Request(t, port, "POST", "/gov/proposals", jsonStr)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
|
||||||
|
@ -1296,7 +1312,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, proposalID int64) (resultTx ctypes.ResultBroadcastTxCommit) {
|
func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, proposalID int64, amount int64) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||||
|
|
||||||
acc := getAccount(t, port, proposerAddr)
|
acc := getAccount(t, port, proposerAddr)
|
||||||
accnum := acc.GetAccountNumber()
|
accnum := acc.GetAccountNumber()
|
||||||
|
@ -1307,7 +1323,7 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk
|
||||||
// deposit on proposal
|
// deposit on proposal
|
||||||
jsonStr := []byte(fmt.Sprintf(`{
|
jsonStr := []byte(fmt.Sprintf(`{
|
||||||
"depositer": "%s",
|
"depositer": "%s",
|
||||||
"amount": [{ "denom": "steak", "amount": "5" }],
|
"amount": [{ "denom": "steak", "amount": "%d" }],
|
||||||
"base_req": {
|
"base_req": {
|
||||||
"name": "%s",
|
"name": "%s",
|
||||||
"password": "%s",
|
"password": "%s",
|
||||||
|
@ -1315,7 +1331,7 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk
|
||||||
"account_number":"%d",
|
"account_number":"%d",
|
||||||
"sequence": "%d"
|
"sequence": "%d"
|
||||||
}
|
}
|
||||||
}`, proposerAddr, name, password, chainID, accnum, sequence))
|
}`, proposerAddr, amount, name, password, chainID, accnum, sequence))
|
||||||
res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/deposits", proposalID), jsonStr)
|
res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/deposits", proposalID), jsonStr)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue