cosmos-sdk/x/params/client/cli/tx_test.go
Alessio Treglia f51f5e6784
testutil: new TempFile function, simplify WriteToNewTempFile (#8123)
Files returned by WriteToNewTempFile are cleaned up
automatically at the end of a test case execution.
WriteToNewTempFile now relies on the TB.TempDir()
function provided by the testing std package.

TempFile returns a temporary file that can be used
within a test case and is automatically removed
at the end of the test execution.
2020-12-09 18:27:20 +00:00

43 lines
968 B
Go

package cli
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/x/params/client/utils"
)
func TestParseProposal(t *testing.T) {
cdc := codec.NewLegacyAmino()
okJSON := testutil.WriteToNewTempFile(t, `
{
"title": "Staking Param Change",
"description": "Update max validators",
"changes": [
{
"subspace": "staking",
"key": "MaxValidators",
"value": 1
}
],
"deposit": "1000stake"
}
`)
proposal, err := utils.ParseParamChangeProposalJSON(cdc, okJSON.Name())
require.NoError(t, err)
require.Equal(t, "Staking Param Change", proposal.Title)
require.Equal(t, "Update max validators", proposal.Description)
require.Equal(t, "1000stake", proposal.Deposit)
require.Equal(t, utils.ParamChangesJSON{
{
Subspace: "staking",
Key: "MaxValidators",
Value: []byte{0x31},
},
}, proposal.Changes)
}