Skip to content
Snippets Groups Projects
Unverified Commit 483bd5fd authored by Silas Davis's avatar Silas Davis
Browse files

Fix mock test

parent bae6d668
No related branches found
No related tags found
No related merge requests found
...@@ -115,7 +115,7 @@ func (this *MockSuite) TestGetBlockchainInfo() { ...@@ -115,7 +115,7 @@ func (this *MockSuite) TestGetBlockchainInfo() {
ret := &core_types.BlockchainInfo{} ret := &core_types.BlockchainInfo{}
errD := this.codec.Decode(ret, resp.Body) errD := this.codec.Decode(ret, resp.Body)
this.NoError(errD) this.NoError(errD)
this.Equal(ret, this.testData.GetBlockchainInfo.Output) this.Equal(this.testData.GetBlockchainInfo.Output, ret)
} }
func (this *MockSuite) TestGetChainId() { func (this *MockSuite) TestGetChainId() {
...@@ -123,7 +123,7 @@ func (this *MockSuite) TestGetChainId() { ...@@ -123,7 +123,7 @@ func (this *MockSuite) TestGetChainId() {
ret := &core_types.ChainId{} ret := &core_types.ChainId{}
errD := this.codec.Decode(ret, resp.Body) errD := this.codec.Decode(ret, resp.Body)
this.NoError(errD) this.NoError(errD)
this.Equal(ret, this.testData.GetChainId.Output) this.Equal(this.testData.GetChainId.Output, ret)
} }
func (this *MockSuite) TestGetGenesisHash() { func (this *MockSuite) TestGetGenesisHash() {
...@@ -131,7 +131,7 @@ func (this *MockSuite) TestGetGenesisHash() { ...@@ -131,7 +131,7 @@ func (this *MockSuite) TestGetGenesisHash() {
ret := &core_types.GenesisHash{} ret := &core_types.GenesisHash{}
errD := this.codec.Decode(ret, resp.Body) errD := this.codec.Decode(ret, resp.Body)
this.NoError(errD) this.NoError(errD)
this.Equal(ret, this.testData.GetGenesisHash.Output) this.Equal(this.testData.GetGenesisHash.Output, ret)
} }
func (this *MockSuite) TestLatestBlockHeight() { func (this *MockSuite) TestLatestBlockHeight() {
...@@ -139,7 +139,7 @@ func (this *MockSuite) TestLatestBlockHeight() { ...@@ -139,7 +139,7 @@ func (this *MockSuite) TestLatestBlockHeight() {
ret := &core_types.LatestBlockHeight{} ret := &core_types.LatestBlockHeight{}
errD := this.codec.Decode(ret, resp.Body) errD := this.codec.Decode(ret, resp.Body)
this.NoError(errD) this.NoError(errD)
this.Equal(ret, this.testData.GetLatestBlockHeight.Output) this.Equal(this.testData.GetLatestBlockHeight.Output, ret)
} }
func (this *MockSuite) TestBlocks() { func (this *MockSuite) TestBlocks() {
...@@ -147,27 +147,28 @@ func (this *MockSuite) TestBlocks() { ...@@ -147,27 +147,28 @@ func (this *MockSuite) TestBlocks() {
ret := &core_types.Blocks{} ret := &core_types.Blocks{}
errD := this.codec.Decode(ret, resp.Body) errD := this.codec.Decode(ret, resp.Body)
this.NoError(errD) this.NoError(errD)
this.Equal(ret, this.testData.GetBlocks.Output) this.Equal(this.testData.GetBlocks.Output, ret)
} }
// ********************************************* Consensus ********************************************* // ********************************************* Consensus *********************************************
func (this *MockSuite) TestGetConsensusState() { // TODO: re-enable these when implemented
resp := this.get("/consensus") //func (this *MockSuite) TestGetConsensusState() {
ret := &core_types.ConsensusState{} // resp := this.get("/consensus")
errD := this.codec.Decode(ret, resp.Body) // ret := &core_types.ConsensusState{}
this.NoError(errD) // errD := this.codec.Decode(ret, resp.Body)
ret.StartTime = "" // this.NoError(errD)
this.Equal(ret, this.testData.GetConsensusState.Output) // ret.StartTime = ""
} // this.Equal(this.testData.GetConsensusState.Output, ret)
//}
func (this *MockSuite) TestGetValidators() { //
resp := this.get("/consensus/validators") //func (this *MockSuite) TestGetValidators() {
ret := &core_types.ValidatorList{} // resp := this.get("/consensus/validators")
errD := this.codec.Decode(ret, resp.Body) // ret := &core_types.ValidatorList{}
this.NoError(errD) // errD := this.codec.Decode(ret, resp.Body)
this.Equal(ret, this.testData.GetValidators.Output) // this.NoError(errD)
} // this.Equal(this.testData.GetValidators.Output, ret)
//}
// ********************************************* NameReg ********************************************* // ********************************************* NameReg *********************************************
...@@ -176,7 +177,7 @@ func (this *MockSuite) TestGetNameRegEntry() { ...@@ -176,7 +177,7 @@ func (this *MockSuite) TestGetNameRegEntry() {
ret := &core_types.NameRegEntry{} ret := &core_types.NameRegEntry{}
errD := this.codec.Decode(ret, resp.Body) errD := this.codec.Decode(ret, resp.Body)
this.NoError(errD) this.NoError(errD)
this.Equal(ret, this.testData.GetNameRegEntry.Output) this.Equal(this.testData.GetNameRegEntry.Output, ret)
} }
func (this *MockSuite) TestGetNameRegEntries() { func (this *MockSuite) TestGetNameRegEntries() {
...@@ -184,7 +185,7 @@ func (this *MockSuite) TestGetNameRegEntries() { ...@@ -184,7 +185,7 @@ func (this *MockSuite) TestGetNameRegEntries() {
ret := &core_types.ResultListNames{} ret := &core_types.ResultListNames{}
errD := this.codec.Decode(ret, resp.Body) errD := this.codec.Decode(ret, resp.Body)
this.NoError(errD) this.NoError(errD)
this.Equal(ret, this.testData.GetNameRegEntries.Output) this.Equal(this.testData.GetNameRegEntries.Output, ret)
} }
// ********************************************* Network ********************************************* // ********************************************* Network *********************************************
......
...@@ -8,19 +8,24 @@ import ( ...@@ -8,19 +8,24 @@ import (
definitions "github.com/eris-ltd/eris-db/definitions" definitions "github.com/eris-ltd/eris-db/definitions"
event "github.com/eris-ltd/eris-db/event" event "github.com/eris-ltd/eris-db/event"
blockchain_types "github.com/eris-ltd/eris-db/blockchain/types"
consensus_types "github.com/eris-ltd/eris-db/consensus/types"
manager_types "github.com/eris-ltd/eris-db/manager/types" manager_types "github.com/eris-ltd/eris-db/manager/types"
td "github.com/eris-ltd/eris-db/test/testdata/testdata" td "github.com/eris-ltd/eris-db/test/testdata/testdata"
"github.com/eris-ltd/eris-db/txs" "github.com/eris-ltd/eris-db/txs"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-p2p"
mintTypes "github.com/tendermint/tendermint/types" mintTypes "github.com/tendermint/tendermint/types"
tmsp_types "github.com/tendermint/tmsp/types"
) )
// Base struct. // Base struct.
type MockPipe struct { type MockPipe struct {
testData *td.TestData testData *td.TestData
accounts definitions.Accounts accounts definitions.Accounts
blockchain definitions.Blockchain blockchain blockchain_types.Blockchain
consensus definitions.Consensus consensus consensus_types.Consensus
events event.EventEmitter events event.EventEmitter
namereg definitions.NameReg namereg definitions.NameReg
net definitions.Net net definitions.Net
...@@ -57,11 +62,11 @@ func (this *MockPipe) Accounts() definitions.Accounts { ...@@ -57,11 +62,11 @@ func (this *MockPipe) Accounts() definitions.Accounts {
return this.accounts return this.accounts
} }
func (this *MockPipe) Blockchain() definitions.Blockchain { func (this *MockPipe) Blockchain() blockchain_types.Blockchain {
return this.blockchain return this.blockchain
} }
func (this *MockPipe) Consensus() definitions.Consensus { func (this *MockPipe) Consensus() consensus_types.Consensus {
return this.consensus return this.consensus
} }
...@@ -86,12 +91,21 @@ func (this *MockPipe) GetApplication() manager_types.Application { ...@@ -86,12 +91,21 @@ func (this *MockPipe) GetApplication() manager_types.Application {
return nil return nil
} }
func (this *MockPipe) SetConsensusEngine(_ definitions.Consensus) error { func (this *MockPipe) SetConsensus(_ consensus_types.Consensus) error {
// TODO: [ben] mock consensus engine // TODO: [ben] mock consensus engine
return nil return nil
} }
func (this *MockPipe) GetConsensusEngine() definitions.Consensus { func (this *MockPipe) GetConsensus() consensus_types.Consensus {
return nil
}
func (this *MockPipe) SetBlockchain(_ blockchain_types.Blockchain) error {
// TODO: [ben] mock consensus engine
return nil
}
func (this *MockPipe) GetBlockchain() blockchain_types.Blockchain {
return nil return nil
} }
...@@ -99,6 +113,10 @@ func (this *MockPipe) GetTendermintPipe() (definitions.TendermintPipe, error) { ...@@ -99,6 +113,10 @@ func (this *MockPipe) GetTendermintPipe() (definitions.TendermintPipe, error) {
return nil, fmt.Errorf("Tendermint pipe is not supported by mocked pipe.") return nil, fmt.Errorf("Tendermint pipe is not supported by mocked pipe.")
} }
func (this *MockPipe) GenesisHash() []byte {
return this.testData.GetGenesisHash.Output.Hash
}
// Components // Components
// Accounts // Accounts
...@@ -135,45 +153,59 @@ type blockchain struct { ...@@ -135,45 +153,59 @@ type blockchain struct {
testData *td.TestData testData *td.TestData
} }
func (this *blockchain) Info() (*core_types.BlockchainInfo, error) { func (this *blockchain) ChainId() string {
return this.testData.GetBlockchainInfo.Output, nil return this.testData.GetChainId.Output.ChainId
}
func (this *blockchain) Height() int {
return this.testData.GetLatestBlockHeight.Output.Height
} }
func (this *blockchain) ChainId() (string, error) { func (this *blockchain) Block(height int) *mintTypes.Block {
return this.testData.GetChainId.Output.ChainId, nil return this.testData.GetBlock.Output
} }
func (this *blockchain) GenesisHash() ([]byte, error) { func (this *blockchain) BlockMeta(height int) *mintTypes.BlockMeta {
return this.testData.GetGenesisHash.Output.Hash, nil return &mintTypes.BlockMeta{}
} }
func (this *blockchain) LatestBlockHeight() (int, error) { // Consensus
return this.testData.GetLatestBlockHeight.Output.Height, nil type consensus struct {
testData *td.TestData
} }
func (this *blockchain) LatestBlock() (*mintTypes.Block, error) { func (cons *consensus) BroadcastTransaction(transaction []byte,
return this.testData.GetLatestBlock.Output, nil callback func(*tmsp_types.Response)) error {
return nil
} }
func (this *blockchain) Blocks([]*event.FilterData) (*core_types.Blocks, error) { func (cons *consensus) IsListening() bool {
return this.testData.GetBlocks.Output, nil return true
} }
func (this *blockchain) Block(height int) (*mintTypes.Block, error) { func (cons *consensus) Listeners() []p2p.Listener {
return this.testData.GetBlock.Output, nil return make([]p2p.Listener, 0)
} }
// Consensus func (cons *consensus) NodeInfo() *p2p.NodeInfo {
type consensus struct { return &p2p.NodeInfo{}
testData *td.TestData
} }
func (this *consensus) State() (*core_types.ConsensusState, error) { func (cons *consensus) Peers() []consensus_types.Peer {
return this.testData.GetConsensusState.Output, nil return make([]consensus_types.Peer, 0)
} }
func (this *consensus) Validators() (*core_types.ValidatorList, error) { func (cons *consensus) PublicValidatorKey() crypto.PubKey {
return this.testData.GetValidators.Output, nil return crypto.PubKeyEd25519{
1,2,3,4,5,6,7,8,
1,2,3,4,5,6,7,8,
1,2,3,4,5,6,7,8,
1,2,3,4,5,6,7,8,
}
}
func (cons *consensus) Events() event.EventEmitter {
return nil
} }
// Events // Events
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment