Skip to content

Commit

Permalink
change require.Equal to assert.JSONEq
Browse files Browse the repository at this point in the history
clear migration test
  • Loading branch information
yun-yeo committed Jul 8, 2021
1 parent 040dd15 commit dac94d0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 68 deletions.
3 changes: 2 additions & 1 deletion x/market/legacy/v05/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -59,5 +60,5 @@ func TestMigrate(t *testing.T) {
}
}`

require.Equal(t, expected, string(indentedBz))
assert.JSONEq(t, expected, string(indentedBz))
}
71 changes: 26 additions & 45 deletions x/oracle/legacy/v05/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -40,35 +41,20 @@ func TestMigrate(t *testing.T) {
require.NoError(t, err)

oracleGenState := v04oracle.GenesisState{
FeederDelegations: map[string]sdk.AccAddress{
"terravaloper13vs2znvhdcy948ejsh7p8p22j8l4n4y07qkhsn": feeder2,
"terravaloper1mx72uukvzqtzhc6gde7shrjqfu5srk22v3yx7a": feeder,
},
ExchangeRates: map[string]sdk.Dec{
core.MicroSDRDenom: sdk.NewDec(1800),
core.MicroUSDDenom: sdk.NewDec(1700),
},
ExchangeRatePrevotes: []v04oracle.ExchangeRatePrevote{},
ExchangeRateVotes: []v04oracle.ExchangeRateVote{},
MissCounters: map[string]int64{
"terravaloper13vs2znvhdcy948ejsh7p8p22j8l4n4y07qkhsn": 321,
"terravaloper1mx72uukvzqtzhc6gde7shrjqfu5srk22v3yx7a": 123,
},
AggregateExchangeRatePrevotes: []v04oracle.AggregateExchangeRatePrevote{
{
Hash: voteHash,
Voter: voter2,
SubmitBlock: 100,
Voter: voter2,
},
{
Hash: voteHash,
Voter: voter,
SubmitBlock: 100,
Voter: voter,
},
},
AggregateExchangeRateVotes: []v04oracle.AggregateExchangeRateVote{
{
Voter: voter2,
ExchangeRateTuples: v04oracle.ExchangeRateTuples{
{
Denom: core.MicroSDRDenom,
Expand All @@ -79,9 +65,9 @@ func TestMigrate(t *testing.T) {
ExchangeRate: sdk.NewDec(1700),
},
},
Voter: voter2,
},
{
Voter: voter,
ExchangeRateTuples: v04oracle.ExchangeRateTuples{
{
Denom: core.MicroSDRDenom,
Expand All @@ -92,20 +78,29 @@ func TestMigrate(t *testing.T) {
ExchangeRate: sdk.NewDec(1700),
},
},
Voter: voter,
},
},
TobinTaxes: map[string]sdk.Dec{
core.MicroSDRDenom: sdk.NewDecWithPrec(1, 2),
core.MicroUSDDenom: sdk.NewDecWithPrec(2, 2),
ExchangeRates: map[string]sdk.Dec{
core.MicroSDRDenom: sdk.NewDec(1800),
core.MicroUSDDenom: sdk.NewDec(1700),
},
FeederDelegations: map[string]sdk.AccAddress{
"terravaloper13vs2znvhdcy948ejsh7p8p22j8l4n4y07qkhsn": feeder2,
"terravaloper1mx72uukvzqtzhc6gde7shrjqfu5srk22v3yx7a": feeder,
},
MissCounters: map[string]int64{
"terravaloper13vs2znvhdcy948ejsh7p8p22j8l4n4y07qkhsn": 321,
"terravaloper1mx72uukvzqtzhc6gde7shrjqfu5srk22v3yx7a": 123,
},
Params: v04oracle.Params{
VotePeriod: 100,
VoteThreshold: sdk.NewDecWithPrec(5, 1),
MinValidPerWindow: sdk.NewDecWithPrec(5, 2),
RewardBand: sdk.NewDecWithPrec(7, 2),
RewardDistributionWindow: 100,
SlashFraction: sdk.NewDecWithPrec(1, 3),
SlashWindow: 100,
MinValidPerWindow: sdk.NewDecWithPrec(5, 2),
VotePeriod: 100,
VoteThreshold: sdk.NewDecWithPrec(5, 1),
Whitelist: v04oracle.DenomList{
{
Name: core.MicroSDRDenom,
Expand All @@ -117,6 +112,12 @@ func TestMigrate(t *testing.T) {
},
},
},
TobinTaxes: map[string]sdk.Dec{
core.MicroSDRDenom: sdk.NewDecWithPrec(1, 2),
core.MicroUSDDenom: sdk.NewDecWithPrec(2, 2),
},
ExchangeRatePrevotes: []v04oracle.ExchangeRatePrevote{},
ExchangeRateVotes: []v04oracle.ExchangeRateVote{},
}

migrated := v05oracle.Migrate(oracleGenState)
Expand Down Expand Up @@ -236,25 +237,5 @@ func TestMigrate(t *testing.T) {
]
}`

areEqualJSON(t, expected, string(indentedBz))
}

func areEqualJSON(t *testing.T, s1, s2 string) {
var o1 interface{}
var o2 interface{}

var err error
err = json.Unmarshal([]byte(s1), &o1)
require.NoError(t, err)

err = json.Unmarshal([]byte(s2), &o2)
require.NoError(t, err)

bz1, err := json.Marshal(o1)
require.NoError(t, err)

bz2, err := json.Marshal(o2)
require.NoError(t, err)

require.Equal(t, bz1, bz2)
assert.JSONEq(t, expected, string(indentedBz))
}
23 changes: 2 additions & 21 deletions x/treasury/legacy/v05/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -181,25 +182,5 @@ func TestMigrate(t *testing.T) {
"tax_rate": "0.020000000000000000"
}`

areEqualJSON(t, expected, string(indentedBz))
}

func areEqualJSON(t *testing.T, s1, s2 string) {
var o1 interface{}
var o2 interface{}

var err error
err = json.Unmarshal([]byte(s1), &o1)
require.NoError(t, err)

err = json.Unmarshal([]byte(s2), &o2)
require.NoError(t, err)

bz1, err := json.Marshal(o1)
require.NoError(t, err)

bz2, err := json.Marshal(o2)
require.NoError(t, err)

require.Equal(t, bz1, bz2)
assert.JSONEq(t, expected, string(indentedBz))
}
3 changes: 2 additions & 1 deletion x/wasm/legacy/v05/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -195,5 +196,5 @@ func TestMigrate(t *testing.T) {
"max_contract_size": "614400"
}
}`
require.Equal(t, expected, string(indentedBz))
assert.JSONEq(t, expected, string(indentedBz))
}

0 comments on commit dac94d0

Please sign in to comment.