|
@ -7,11 +7,8 @@ import ( |
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
"github.com/stretchr/testify/assert" |
|
|
"github.com/stretchr/testify/require" |
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
|
|
|
|
abci "github.com/tendermint/abci/types" |
|
|
abci "github.com/tendermint/abci/types" |
|
|
|
|
|
|
|
|
crypto "github.com/tendermint/go-crypto" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/tendermint/go-crypto" |
|
|
cmn "github.com/tendermint/tmlibs/common" |
|
|
cmn "github.com/tendermint/tmlibs/common" |
|
|
dbm "github.com/tendermint/tmlibs/db" |
|
|
dbm "github.com/tendermint/tmlibs/db" |
|
|
|
|
|
|
|
@ -42,7 +39,7 @@ func TestStateCopy(t *testing.T) { |
|
|
stateCopy := state.Copy() |
|
|
stateCopy := state.Copy() |
|
|
|
|
|
|
|
|
assert.True(state.Equals(stateCopy), |
|
|
assert.True(state.Equals(stateCopy), |
|
|
cmn.Fmt(`expected state and its copy to be identical. got %v\n expected %v\n`, |
|
|
|
|
|
|
|
|
cmn.Fmt("expected state and its copy to be identical.\ngot: %v\nexpected: %v\n", |
|
|
stateCopy, state)) |
|
|
stateCopy, state)) |
|
|
|
|
|
|
|
|
stateCopy.LastBlockHeight++ |
|
|
stateCopy.LastBlockHeight++ |
|
@ -62,7 +59,7 @@ func TestStateSaveLoad(t *testing.T) { |
|
|
|
|
|
|
|
|
loadedState := LoadState(stateDB) |
|
|
loadedState := LoadState(stateDB) |
|
|
assert.True(state.Equals(loadedState), |
|
|
assert.True(state.Equals(loadedState), |
|
|
cmn.Fmt(`expected state and its copy to be identical. got %v\n expected %v\n`, |
|
|
|
|
|
|
|
|
cmn.Fmt("expected state and its copy to be identical.\ngot: %v\nexpected: %v\n", |
|
|
loadedState, state)) |
|
|
loadedState, state)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -78,8 +75,8 @@ func TestABCIResponsesSaveLoad1(t *testing.T) { |
|
|
// build mock responses
|
|
|
// build mock responses
|
|
|
block := makeBlock(state, 2) |
|
|
block := makeBlock(state, 2) |
|
|
abciResponses := NewABCIResponses(block) |
|
|
abciResponses := NewABCIResponses(block) |
|
|
abciResponses.DeliverTx[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Tags: []cmn.KVPair{}} |
|
|
|
|
|
abciResponses.DeliverTx[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Tags: []cmn.KVPair{}} |
|
|
|
|
|
|
|
|
abciResponses.DeliverTx[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Tags: nil} |
|
|
|
|
|
abciResponses.DeliverTx[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Tags: nil} |
|
|
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{ |
|
|
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{ |
|
|
{ |
|
|
{ |
|
|
PubKey: crypto.GenPrivKeyEd25519().PubKey().Bytes(), |
|
|
PubKey: crypto.GenPrivKeyEd25519().PubKey().Bytes(), |
|
@ -88,11 +85,11 @@ func TestABCIResponsesSaveLoad1(t *testing.T) { |
|
|
}} |
|
|
}} |
|
|
|
|
|
|
|
|
saveABCIResponses(stateDB, block.Height, abciResponses) |
|
|
saveABCIResponses(stateDB, block.Height, abciResponses) |
|
|
loadedAbciResponses, err := LoadABCIResponses(stateDB, block.Height) |
|
|
|
|
|
|
|
|
loadedABCIResponses, err := LoadABCIResponses(stateDB, block.Height) |
|
|
assert.Nil(err) |
|
|
assert.Nil(err) |
|
|
assert.Equal(abciResponses, loadedAbciResponses, |
|
|
|
|
|
cmn.Fmt(`ABCIResponses don't match: Got %v, Expected %v`, loadedAbciResponses, |
|
|
|
|
|
abciResponses)) |
|
|
|
|
|
|
|
|
assert.Equal(abciResponses, loadedABCIResponses, |
|
|
|
|
|
cmn.Fmt("ABCIResponses don't match:\ngot: %v\nexpected: %v\n", |
|
|
|
|
|
loadedABCIResponses, abciResponses)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TestResultsSaveLoad tests saving and loading abci results.
|
|
|
// TestResultsSaveLoad tests saving and loading abci results.
|
|
@ -109,8 +106,8 @@ func TestABCIResponsesSaveLoad2(t *testing.T) { |
|
|
expected types.ABCIResults |
|
|
expected types.ABCIResults |
|
|
}{ |
|
|
}{ |
|
|
0: { |
|
|
0: { |
|
|
[]*abci.ResponseDeliverTx{}, |
|
|
|
|
|
types.ABCIResults{}, |
|
|
|
|
|
|
|
|
nil, |
|
|
|
|
|
nil, |
|
|
}, |
|
|
}, |
|
|
1: { |
|
|
1: { |
|
|
[]*abci.ResponseDeliverTx{ |
|
|
[]*abci.ResponseDeliverTx{ |
|
@ -129,12 +126,12 @@ func TestABCIResponsesSaveLoad2(t *testing.T) { |
|
|
}}, |
|
|
}}, |
|
|
}, |
|
|
}, |
|
|
types.ABCIResults{ |
|
|
types.ABCIResults{ |
|
|
{383, []byte{}}, |
|
|
|
|
|
|
|
|
{383, nil}, |
|
|
{0, []byte("Gotcha!")}, |
|
|
{0, []byte("Gotcha!")}, |
|
|
}}, |
|
|
}}, |
|
|
3: { |
|
|
3: { |
|
|
nil, |
|
|
nil, |
|
|
types.ABCIResults{}, |
|
|
|
|
|
|
|
|
nil, |
|
|
}, |
|
|
}, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -430,7 +427,7 @@ func makeHeaderPartsResponsesValPubKeyChange(state State, height int64, |
|
|
|
|
|
|
|
|
block := makeBlock(state, height) |
|
|
block := makeBlock(state, height) |
|
|
abciResponses := &ABCIResponses{ |
|
|
abciResponses := &ABCIResponses{ |
|
|
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{}}, |
|
|
|
|
|
|
|
|
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// if the pubkey is new, remove the old and add the new
|
|
|
// if the pubkey is new, remove the old and add the new
|
|
@ -452,7 +449,7 @@ func makeHeaderPartsResponsesValPowerChange(state State, height int64, |
|
|
|
|
|
|
|
|
block := makeBlock(state, height) |
|
|
block := makeBlock(state, height) |
|
|
abciResponses := &ABCIResponses{ |
|
|
abciResponses := &ABCIResponses{ |
|
|
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{}}, |
|
|
|
|
|
|
|
|
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// if the pubkey is new, remove the old and add the new
|
|
|
// if the pubkey is new, remove the old and add the new
|
|
|