-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from wukongcheng/silei/cli_test
R4R: cli_test
- Loading branch information
Showing
8 changed files
with
581 additions
and
208 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,92 @@ | ||
package clitest | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
"github.com/cosmos/cosmos-sdk/tests" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
|
||
"github.com/irisnet/irishub/app" | ||
) | ||
|
||
func init() { | ||
irisHome, iriscliHome = getTestingHomeDirs() | ||
} | ||
|
||
func TestIrisCLIBankSend(t *testing.T) { | ||
tests.ExecuteT(t, fmt.Sprintf("iris --home=%s unsafe_reset_all", irisHome), "") | ||
executeWrite(t, fmt.Sprintf("iriscli keys delete --home=%s foo", iriscliHome), app.DefaultKeyPass) | ||
executeWrite(t, fmt.Sprintf("iriscli keys delete --home=%s bar", iriscliHome), app.DefaultKeyPass) | ||
chainID := executeInit(t, fmt.Sprintf("iris init -o --name=foo --home=%s --home-client=%s", irisHome, iriscliHome)) | ||
executeWrite(t, fmt.Sprintf("iriscli keys add --home=%s bar", iriscliHome), app.DefaultKeyPass) | ||
|
||
err := modifyGenesisFile(t, irisHome) | ||
require.NoError(t, err) | ||
|
||
// get a free port, also setup some common flags | ||
servAddr, port, err := server.FreeTCPAddr() | ||
require.NoError(t, err) | ||
flags := fmt.Sprintf("--home=%s --node=%v --chain-id=%v", iriscliHome, servAddr, chainID) | ||
|
||
// start iris server | ||
proc := tests.GoExecuteTWithStdout(t, fmt.Sprintf("iris start --home=%s --rpc.laddr=%v", irisHome, servAddr)) | ||
|
||
defer proc.Stop(false) | ||
tests.WaitForTMStart(port) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf("iriscli keys show foo --output=json --home=%s", iriscliHome)) | ||
barAddr, _ := executeGetAddrPK(t, fmt.Sprintf("iriscli keys show bar --output=json --home=%s", iriscliHome)) | ||
|
||
fooAcc := executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", fooAddr, flags)) | ||
fooCoin := convertToIrisBaseAccount(t, fooAcc) | ||
require.Equal(t, "1000000000000iris", fooCoin) | ||
|
||
executeWrite(t, fmt.Sprintf("iriscli bank send %v --amount=10iris --to=%s --from=foo --gas=10000 --fee=0.04iris", flags, barAddr), app.DefaultKeyPass) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
barAcc := executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", barAddr, flags)) | ||
barCoin := convertToIrisBaseAccount(t, barAcc) | ||
require.Equal(t, "10iris", barCoin) | ||
|
||
fooAcc = executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", fooAddr, flags)) | ||
fooCoin = convertToIrisBaseAccount(t, fooAcc) | ||
num := getAmuntFromCoinStr(t, fooCoin) | ||
|
||
if !(num > 999999999989 && num < 999999999990) { | ||
t.Error("Test Failed: (999999999989, 999999999990) expected, recieved: {}", num) | ||
} | ||
|
||
// test autosequencing | ||
executeWrite(t, fmt.Sprintf("iriscli bank send %v --amount=10iris --to=%s --from=foo --gas=10000 --fee=0.04iris", flags, barAddr), app.DefaultKeyPass) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
barAcc = executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", barAddr, flags)) | ||
barCoin = convertToIrisBaseAccount(t, barAcc) | ||
require.Equal(t, "20iris", barCoin) | ||
|
||
fooAcc = executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", fooAddr, flags)) | ||
fooCoin = convertToIrisBaseAccount(t, fooAcc) | ||
num = getAmuntFromCoinStr(t, fooCoin) | ||
|
||
if !(num > 999999999979 && num < 999999999980) { | ||
t.Error("Test Failed: (999999999979, 999999999980) expected, recieved: {}", num) | ||
} | ||
|
||
// test memo | ||
executeWrite(t, fmt.Sprintf("iriscli bank send %v --amount=10iris --to=%s --from=foo --memo 'testmemo' --gas=10000 --fee=0.04iris", flags, barAddr), app.DefaultKeyPass) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
barAcc = executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", barAddr, flags)) | ||
barCoin = convertToIrisBaseAccount(t, barAcc) | ||
require.Equal(t, "30iris", barCoin) | ||
|
||
fooAcc = executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", fooAddr, flags)) | ||
fooCoin = convertToIrisBaseAccount(t, fooAcc) | ||
num = getAmuntFromCoinStr(t, fooCoin) | ||
|
||
if !(num > 999999999969 && num < 999999999970) { | ||
t.Error("Test Failed: (999999999969, 999999999970) expected, recieved: {}", num) | ||
} | ||
} |
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,135 @@ | ||
package clitest | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
"github.com/cosmos/cosmos-sdk/tests" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
|
||
"github.com/irisnet/irishub/app" | ||
"github.com/irisnet/irishub/modules/gov" | ||
) | ||
|
||
func init() { | ||
irisHome, iriscliHome = getTestingHomeDirs() | ||
} | ||
|
||
func TestIrisCLISubmitProposal(t *testing.T) { | ||
tests.ExecuteT(t, fmt.Sprintf("iris --home=%s unsafe_reset_all", irisHome), "") | ||
executeWrite(t, fmt.Sprintf("iriscli keys delete --home=%s foo", iriscliHome), app.DefaultKeyPass) | ||
executeWrite(t, fmt.Sprintf("iriscli keys delete --home=%s bar", iriscliHome), app.DefaultKeyPass) | ||
chainID := executeInit(t, fmt.Sprintf("iris init -o --name=foo --home=%s --home-client=%s", irisHome, iriscliHome)) | ||
executeWrite(t, fmt.Sprintf("iriscli keys add --home=%s bar", iriscliHome), app.DefaultKeyPass) | ||
|
||
err := modifyGenesisFile(t, irisHome) | ||
require.NoError(t, err) | ||
|
||
// get a free port, also setup some common flags | ||
servAddr, port, err := server.FreeTCPAddr() | ||
require.NoError(t, err) | ||
flags := fmt.Sprintf("--home=%s --node=%v --chain-id=%v", iriscliHome, servAddr, chainID) | ||
|
||
// start iris server | ||
proc := tests.GoExecuteTWithStdout(t, fmt.Sprintf("iris start --home=%s --rpc.laddr=%v", irisHome, servAddr)) | ||
|
||
defer proc.Stop(false) | ||
tests.WaitForTMStart(port) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf("iriscli keys show foo --output=json --home=%s", iriscliHome)) | ||
|
||
fooAcc := executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", fooAddr, flags)) | ||
fooCoin := convertToIrisBaseAccount(t, fooAcc) | ||
require.Equal(t, "1000000000000iris", fooCoin) | ||
|
||
proposalsQuery := tests.ExecuteT(t, fmt.Sprintf("iriscli gov query-proposals %v", flags), "") | ||
require.Equal(t, "No matching proposals found", proposalsQuery) | ||
|
||
// submit a test proposal | ||
spStr := fmt.Sprintf("iriscli gov submit-proposal %v", flags) | ||
spStr += fmt.Sprintf(" --from=%s", "foo") | ||
spStr += fmt.Sprintf(" --deposit=%s", "5iris") | ||
spStr += fmt.Sprintf(" --type=%s", "Text") | ||
spStr += fmt.Sprintf(" --title=%s", "Test") | ||
spStr += fmt.Sprintf(" --description=%s", "test") | ||
spStr += fmt.Sprintf(" --fee=%s", "0.004iris") | ||
|
||
executeWrite(t, spStr, app.DefaultKeyPass) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
fooAcc = executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", fooAddr, flags)) | ||
fooCoin = convertToIrisBaseAccount(t, fooAcc) | ||
num := getAmuntFromCoinStr(t, fooCoin) | ||
|
||
if !(num > 999999999994 && num < 999999999995) { | ||
t.Error("Test Failed: (999999999994, 999999999995) expected, recieved: {}", num) | ||
} | ||
|
||
proposal1 := executeGetProposal(t, fmt.Sprintf("iriscli gov query-proposal --proposal-id=1 --output=json %v", flags)) | ||
require.Equal(t, int64(1), proposal1.ProposalID) | ||
require.Equal(t, gov.StatusDepositPeriod, proposal1.Status) | ||
|
||
proposalsQuery = tests.ExecuteT(t, fmt.Sprintf("iriscli gov query-proposals %v", flags), "") | ||
require.Equal(t, " 1 - Test", proposalsQuery) | ||
|
||
depositStr := fmt.Sprintf("iriscli gov deposit %v", flags) | ||
depositStr += fmt.Sprintf(" --from=%s", "foo") | ||
depositStr += fmt.Sprintf(" --deposit=%s", "1000iris") | ||
depositStr += fmt.Sprintf(" --proposal-id=%s", "1") | ||
depositStr += fmt.Sprintf(" --fee=%s", "0.004iris") | ||
|
||
executeWrite(t, depositStr, app.DefaultKeyPass) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
fooAcc = executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", fooAddr, flags)) | ||
fooCoin = convertToIrisBaseAccount(t, fooAcc) | ||
num = getAmuntFromCoinStr(t, fooCoin) | ||
|
||
if !(num > 999999998994 && num < 999999998995) { | ||
t.Error("Test Failed: (999999998994, 999999998995) expected, recieved: {}", num) | ||
} | ||
|
||
proposal1 = executeGetProposal(t, fmt.Sprintf("iriscli gov query-proposal --proposal-id=1 --output=json %v", flags)) | ||
require.Equal(t, int64(1), proposal1.ProposalID) | ||
require.Equal(t, gov.StatusVotingPeriod, proposal1.Status) | ||
|
||
voteStr := fmt.Sprintf("iriscli gov vote %v", flags) | ||
voteStr += fmt.Sprintf(" --from=%s", "foo") | ||
voteStr += fmt.Sprintf(" --proposal-id=%s", "1") | ||
voteStr += fmt.Sprintf(" --option=%s", "Yes") | ||
voteStr += fmt.Sprintf(" --fee=%s", "0.004iris") | ||
|
||
executeWrite(t, voteStr, app.DefaultKeyPass) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
vote := executeGetVote(t, fmt.Sprintf("iriscli gov query-vote --proposal-id=1 --voter=%s --output=json %v", fooAddr, flags)) | ||
require.Equal(t, int64(1), vote.ProposalID) | ||
require.Equal(t, gov.OptionYes, vote.Option) | ||
|
||
votes := executeGetVotes(t, fmt.Sprintf("iriscli gov query-votes --proposal-id=1 --output=json %v", flags)) | ||
require.Len(t, votes, 1) | ||
require.Equal(t, int64(1), votes[0].ProposalID) | ||
require.Equal(t, gov.OptionYes, votes[0].Option) | ||
|
||
proposalsQuery = tests.ExecuteT(t, fmt.Sprintf("iriscli gov query-proposals --status=DepositPeriod %v", flags), "") | ||
require.Equal(t, "No matching proposals found", proposalsQuery) | ||
|
||
proposalsQuery = tests.ExecuteT(t, fmt.Sprintf("iriscli gov query-proposals --status=VotingPeriod %v", flags), "") | ||
require.Equal(t, " 1 - Test", proposalsQuery) | ||
|
||
// submit a second test proposal | ||
spStr = fmt.Sprintf("iriscli gov submit-proposal %v", flags) | ||
spStr += fmt.Sprintf(" --from=%s", "foo") | ||
spStr += fmt.Sprintf(" --deposit=%s", "5iris") | ||
spStr += fmt.Sprintf(" --type=%s", "Text") | ||
spStr += fmt.Sprintf(" --title=%s", "Apples") | ||
spStr += fmt.Sprintf(" --description=%s", "test") | ||
spStr += fmt.Sprintf(" --fee=%s", "0.004iris") | ||
|
||
executeWrite(t, spStr, app.DefaultKeyPass) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
proposalsQuery = tests.ExecuteT(t, fmt.Sprintf("iriscli gov query-proposals --latest=1 %v", flags), "") | ||
require.Equal(t, " 2 - Apples", proposalsQuery) | ||
} |
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,95 @@ | ||
package clitest | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
"github.com/cosmos/cosmos-sdk/tests" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
|
||
"github.com/irisnet/irishub/app" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func init() { | ||
irisHome, iriscliHome = getTestingHomeDirs() | ||
} | ||
|
||
func TestIrisCLIStakeCreateValidator(t *testing.T) { | ||
tests.ExecuteT(t, fmt.Sprintf("iris --home=%s unsafe_reset_all", irisHome), "") | ||
executeWrite(t, fmt.Sprintf("iriscli keys delete --home=%s foo", iriscliHome), app.DefaultKeyPass) | ||
executeWrite(t, fmt.Sprintf("iriscli keys delete --home=%s bar", iriscliHome), app.DefaultKeyPass) | ||
chainID := executeInit(t, fmt.Sprintf("iris init -o --name=foo --home=%s --home-client=%s", irisHome, iriscliHome)) | ||
executeWrite(t, fmt.Sprintf("iriscli keys add --home=%s bar", iriscliHome), app.DefaultKeyPass) | ||
|
||
err := modifyGenesisFile(t, irisHome) | ||
require.NoError(t, err) | ||
|
||
// get a free port, also setup some common flags | ||
servAddr, port, err := server.FreeTCPAddr() | ||
require.NoError(t, err) | ||
flags := fmt.Sprintf("--home=%s --node=%v --chain-id=%v", iriscliHome, servAddr, chainID) | ||
|
||
// start iris server | ||
proc := tests.GoExecuteTWithStdout(t, fmt.Sprintf("iris start --home=%s --rpc.laddr=%v", irisHome, servAddr)) | ||
|
||
defer proc.Stop(false) | ||
tests.WaitForTMStart(port) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf("iriscli keys show foo --output=json --home=%s", iriscliHome)) | ||
barAddr, barPubKey := executeGetAddrPK(t, fmt.Sprintf("iriscli keys show bar --output=json --home=%s", iriscliHome)) | ||
barCeshPubKey := sdk.MustBech32ifyValPub(barPubKey) | ||
|
||
executeWrite(t, fmt.Sprintf("iriscli bank send %v --amount=10iris --to=%s --from=foo --gas=10000 --fee=0.04iris", flags, barAddr), app.DefaultKeyPass) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
barAcc := executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", barAddr, flags)) | ||
barCoin := convertToIrisBaseAccount(t, barAcc) | ||
require.Equal(t, "10iris", barCoin) | ||
|
||
fooAcc := executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", fooAddr, flags)) | ||
fooCoin := convertToIrisBaseAccount(t, fooAcc) | ||
num := getAmuntFromCoinStr(t, fooCoin) | ||
|
||
if !(num > 999999999989 && num < 999999999990) { | ||
t.Error("Test Failed: (999999999989, 999999999990) expected, recieved: {}", num) | ||
} | ||
|
||
// create validator | ||
cvStr := fmt.Sprintf("iriscli stake create-validator %v", flags) | ||
cvStr += fmt.Sprintf(" --from=%s", "bar") | ||
cvStr += fmt.Sprintf(" --pubkey=%s", barCeshPubKey) | ||
cvStr += fmt.Sprintf(" --amount=%v", "2iris") | ||
cvStr += fmt.Sprintf(" --moniker=%v", "bar-vally") | ||
cvStr += fmt.Sprintf(" --fee=%s", "0.004iris") | ||
|
||
executeWrite(t, cvStr, app.DefaultKeyPass) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
barAcc = executeGetAccount(t, fmt.Sprintf("iriscli bank account %s %v", barAddr, flags)) | ||
barCoin = convertToIrisBaseAccount(t, barAcc) | ||
num = getAmuntFromCoinStr(t, barCoin) | ||
|
||
if !(num > 7 && num < 8) { | ||
t.Error("Test Failed: (7, 8) expected, recieved: {}", num) | ||
} | ||
|
||
validator := executeGetValidator(t, fmt.Sprintf("iriscli stake validator %s --output=json %v", barAddr, flags)) | ||
require.Equal(t, validator.Owner, barAddr) | ||
require.Equal(t, "2.0000000000", validator.Tokens) | ||
|
||
// unbond a single share | ||
unbondStr := fmt.Sprintf("iriscli stake unbond begin %v", flags) | ||
unbondStr += fmt.Sprintf(" --from=%s", "bar") | ||
unbondStr += fmt.Sprintf(" --address-validator=%s", barAddr) | ||
unbondStr += fmt.Sprintf(" --shares-amount=%v", "1") | ||
unbondStr += fmt.Sprintf(" --fee=%s", "0.004iris") | ||
|
||
success := executeWrite(t, unbondStr, app.DefaultKeyPass) | ||
require.True(t, success) | ||
tests.WaitForNextNBlocksTM(2, port) | ||
|
||
validator = executeGetValidator(t, fmt.Sprintf("iriscli stake validator %s --output=json %v", barAddr, flags)) | ||
require.Equal(t, "1.0000000000", validator.Tokens) | ||
} |
Oops, something went wrong.