Skip to content

Commit

Permalink
meta: Switch the majority of asserts to require
Browse files Browse the repository at this point in the history
Switch most assert statements to require, to ease debugging.
Closes #1418
  • Loading branch information
ValarDragon committed Jun 29, 2018
1 parent fc3dd56 commit 7629a1d
Show file tree
Hide file tree
Showing 65 changed files with 1,176 additions and 1,176 deletions.
138 changes: 69 additions & 69 deletions baseapp/baseapp_test.go

Large diffs are not rendered by default.

136 changes: 68 additions & 68 deletions client/lcd/lcd_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/gaia/app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestToAccount(t *testing.T) {
addr := sdk.Address(priv.PubKey().Address())
authAcc := auth.NewBaseAccountWithAddress(addr)
genAcc := NewGenesisAccount(&authAcc)
assert.Equal(t, authAcc, *genAcc.ToAccount())
require.Equal(t, authAcc, *genAcc.ToAccount())
}

func TestGaiaAppGenTx(t *testing.T) {
Expand Down
42 changes: 21 additions & 21 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,33 @@ func TestGaiaCLISend(t *testing.T) {
require.NoError(t, err)

fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags))
assert.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())

executeWrite(t, fmt.Sprintf("gaiacli send %v --amount=10steak --to=%v --name=foo", flags, barCech), pass)
tests.WaitForNextHeightTM(port)

barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags))
assert.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64())
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags))
assert.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())

// test autosequencing
executeWrite(t, fmt.Sprintf("gaiacli send %v --amount=10steak --to=%v --name=foo", flags, barCech), pass)
tests.WaitForNextHeightTM(port)

barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags))
assert.Equal(t, int64(20), barAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(20), barAcc.GetCoins().AmountOf("steak").Int64())
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags))
assert.Equal(t, int64(30), fooAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(30), fooAcc.GetCoins().AmountOf("steak").Int64())

// test memo
executeWrite(t, fmt.Sprintf("gaiacli send %v --amount=10steak --to=%v --name=foo --memo 'testmemo'", flags, barCech), pass)
tests.WaitForNextHeightTM(port)

barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags))
assert.Equal(t, int64(30), barAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(30), barAcc.GetCoins().AmountOf("steak").Int64())
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags))
assert.Equal(t, int64(20), fooAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(20), fooAcc.GetCoins().AmountOf("steak").Int64())
}

func TestGaiaCLICreateValidator(t *testing.T) {
Expand Down Expand Up @@ -108,9 +108,9 @@ func TestGaiaCLICreateValidator(t *testing.T) {
tests.WaitForNextHeightTM(port)

barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags))
assert.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64())
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags))
assert.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())

// create validator
cvStr := fmt.Sprintf("gaiacli stake create-validator %v", flags)
Expand All @@ -127,8 +127,8 @@ func TestGaiaCLICreateValidator(t *testing.T) {
require.Equal(t, int64(8), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc)

validator := executeGetValidator(t, fmt.Sprintf("gaiacli stake validator %v --output=json %v", barCech, flags))
assert.Equal(t, validator.Owner, barAddr)
assert.Equal(t, "2/1", validator.PoolShares.Amount.String())
require.Equal(t, validator.Owner, barAddr)
require.Equal(t, "2/1", validator.PoolShares.Amount.String())

// unbond a single share
unbondStr := fmt.Sprintf("gaiacli stake unbond %v", flags)
Expand All @@ -145,7 +145,7 @@ func TestGaiaCLICreateValidator(t *testing.T) {
barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags))
require.Equal(t, int64(9), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc)
validator = executeGetValidator(t, fmt.Sprintf("gaiacli stake validator %v --output=json %v", barCech, flags))
assert.Equal(t, "1/1", validator.PoolShares.Amount.String())
require.Equal(t, "1/1", validator.PoolShares.Amount.String())
}

func TestGaiaCLISubmitProposal(t *testing.T) {
Expand All @@ -172,33 +172,33 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.NoError(t, err)

fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags))
assert.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())

executeWrite(t, fmt.Sprintf("gaiacli gov submitproposal %v --proposer=%v --deposit=5steak --type=Text --title=Test --description=test --name=foo", flags, fooCech), pass)
tests.WaitForNextHeightTM(port)

fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags))
assert.Equal(t, int64(45), fooAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(45), fooAcc.GetCoins().AmountOf("steak").Int64())

proposal1 := executeGetProposal(t, fmt.Sprintf("gaiacli gov query-proposal --proposalID=1 --output=json %v", flags))
assert.Equal(t, int64(1), proposal1.ProposalID)
assert.Equal(t, gov.StatusToString(gov.StatusDepositPeriod), proposal1.Status)
require.Equal(t, int64(1), proposal1.ProposalID)
require.Equal(t, gov.StatusToString(gov.StatusDepositPeriod), proposal1.Status)

executeWrite(t, fmt.Sprintf("gaiacli gov deposit %v --depositer=%v --deposit=10steak --proposalID=1 --name=foo", flags, fooCech), pass)
tests.WaitForNextHeightTM(port)

fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags))
assert.Equal(t, int64(35), fooAcc.GetCoins().AmountOf("steak").Int64())
require.Equal(t, int64(35), fooAcc.GetCoins().AmountOf("steak").Int64())
proposal1 = executeGetProposal(t, fmt.Sprintf("gaiacli gov query-proposal --proposalID=1 --output=json %v", flags))
assert.Equal(t, int64(1), proposal1.ProposalID)
assert.Equal(t, gov.StatusToString(gov.StatusVotingPeriod), proposal1.Status)
require.Equal(t, int64(1), proposal1.ProposalID)
require.Equal(t, gov.StatusToString(gov.StatusVotingPeriod), proposal1.Status)

executeWrite(t, fmt.Sprintf("gaiacli gov vote %v --proposalID=1 --voter=%v --option=Yes --name=foo", flags, fooCech), pass)
tests.WaitForNextHeightTM(port)

vote := executeGetVote(t, fmt.Sprintf("gaiacli gov query-vote --proposalID=1 --voter=%v --output=json %v", fooCech, flags))
assert.Equal(t, int64(1), vote.ProposalID)
assert.Equal(t, gov.VoteOptionToString(gov.OptionYes), vote.Option)
require.Equal(t, int64(1), vote.ProposalID)
require.Equal(t, gov.VoteOptionToString(gov.OptionYes), vote.Option)
}

//___________________________________________________________________________________
Expand Down
30 changes: 15 additions & 15 deletions crypto/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func checkAminoBinary(t *testing.T, src byter, dst interface{}, size int) {
bz, err := cdc.MarshalBinaryBare(src)
require.Nil(t, err, "%+v", err)
// Make sure this is compatible with current (Bytes()) encoding.
assert.Equal(t, src.Bytes(), bz, "Amino binary vs Bytes() mismatch")
require.Equal(t, src.Bytes(), bz, "Amino binary vs Bytes() mismatch")
// Make sure we have the expected length.
if size != -1 {
assert.Equal(t, size, len(bz), "Amino binary size mismatch")
require.Equal(t, size, len(bz), "Amino binary size mismatch")
}
// Unmarshal.
err = cdc.UnmarshalBinaryBare(bz, dst)
Expand All @@ -33,10 +33,10 @@ func checkAminoJSON(t *testing.T, src interface{}, dst interface{}, isNil bool)
js, err := cdc.MarshalJSON(src)
require.Nil(t, err, "%+v", err)
if isNil {
assert.Equal(t, string(js), `null`)
require.Equal(t, string(js), `null`)
} else {
assert.Contains(t, string(js), `"type":`)
assert.Contains(t, string(js), `"value":`)
require.Contains(t, string(js), `"type":`)
require.Contains(t, string(js), `"value":`)
}
// Unmarshal.
err = cdc.UnmarshalJSON(js, dst)
Expand Down Expand Up @@ -79,26 +79,26 @@ func TestKeyEncodings(t *testing.T) {
// Check (de/en)codings of PrivKeys.
var priv2, priv3 tcrypto.PrivKey
checkAminoBinary(t, tc.privKey, &priv2, tc.privSize)
assert.EqualValues(t, tc.privKey, priv2)
require.EqualValues(t, tc.privKey, priv2)
checkAminoJSON(t, tc.privKey, &priv3, false) // TODO also check Prefix bytes.
assert.EqualValues(t, tc.privKey, priv3)
require.EqualValues(t, tc.privKey, priv3)

// Check (de/en)codings of Signatures.
var sig1, sig2, sig3 tcrypto.Signature
sig1, err := tc.privKey.Sign([]byte("something"))
assert.NoError(t, err)
require.NoError(t, err)
checkAminoBinary(t, sig1, &sig2, -1) // Signature size changes for Secp anyways.
assert.EqualValues(t, sig1, sig2)
require.EqualValues(t, sig1, sig2)
checkAminoJSON(t, sig1, &sig3, false) // TODO also check Prefix bytes.
assert.EqualValues(t, sig1, sig3)
require.EqualValues(t, sig1, sig3)

// Check (de/en)codings of PubKeys.
pubKey := tc.privKey.PubKey()
var pub2, pub3 tcrypto.PubKey
checkAminoBinary(t, pubKey, &pub2, tc.pubSize)
assert.EqualValues(t, pubKey, pub2)
require.EqualValues(t, pubKey, pub2)
checkAminoJSON(t, pubKey, &pub3, false) // TODO also check Prefix bytes.
assert.EqualValues(t, pubKey, pub3)
require.EqualValues(t, pubKey, pub3)
}
}

Expand All @@ -107,16 +107,16 @@ func TestNilEncodings(t *testing.T) {
// Check nil Signature.
var a, b tcrypto.Signature
checkAminoJSON(t, &a, &b, true)
assert.EqualValues(t, a, b)
require.EqualValues(t, a, b)

// Check nil PubKey.
var c, d tcrypto.PubKey
checkAminoJSON(t, &c, &d, true)
assert.EqualValues(t, c, d)
require.EqualValues(t, c, d)

// Check nil PrivKey.
var e, f tcrypto.PrivKey
checkAminoJSON(t, &e, &f, true)
assert.EqualValues(t, e, f)
require.EqualValues(t, e, f)

}
4 changes: 2 additions & 2 deletions crypto/keys/bip39/wordcodec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

func TestWordCodec_NewMnemonic(t *testing.T) {
_, err := NewMnemonic(FundRaiser)
assert.NoError(t, err, "unexpected error generating fundraiser mnemonic")
require.NoError(t, err, "unexpected error generating fundraiser mnemonic")

_, err = NewMnemonic(FreshKey)
assert.NoError(t, err, "unexpected error generating new 24-word mnemonic")
require.NoError(t, err, "unexpected error generating new 24-word mnemonic")
}
12 changes: 6 additions & 6 deletions crypto/keys/hd/fundraiser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestFundraiserCompatibility(t *testing.T) {

master, ch := ComputeMastersFromSeed(seed)
priv, err := DerivePrivateKeyForPath(master, ch, "44'/118'/0'/0/0")
assert.NoError(t, err)
require.NoError(t, err)
pub := crypto.PrivKeySecp256k1(priv).PubKey()

t.Log("\tNODEJS GOLANG\n")
Expand All @@ -65,16 +65,16 @@ func TestFundraiserCompatibility(t *testing.T) {
t.Logf("PRIV \t%X %X\n", privB, priv)
t.Logf("PUB \t%X %X\n", pubB, pub)

assert.Equal(t, seedB, seed)
assert.Equal(t, master[:], masterB, fmt.Sprintf("Expected masters to match for %d", i))
assert.Equal(t, priv[:], privB, "Expected priv keys to match")
require.Equal(t, seedB, seed)
require.Equal(t, master[:], masterB, fmt.Sprintf("Expected masters to match for %d", i))
require.Equal(t, priv[:], privB, "Expected priv keys to match")
var pubBFixed [33]byte
copy(pubBFixed[:], pubB)
assert.Equal(t, pub, crypto.PubKeySecp256k1(pubBFixed), fmt.Sprintf("Expected pub keys to match for %d", i))
require.Equal(t, pub, crypto.PubKeySecp256k1(pubBFixed), fmt.Sprintf("Expected pub keys to match for %d", i))

addr := pub.Address()
t.Logf("ADDR \t%X %X\n", addrB, addr)
assert.Equal(t, addr, crypto.Address(addrB), fmt.Sprintf("Expected addresses to match %d", i))
require.Equal(t, addr, crypto.Address(addrB), fmt.Sprintf("Expected addresses to match %d", i))

}
}
Loading

0 comments on commit 7629a1d

Please sign in to comment.