From 07bee70ab6ecb0ccc9b8ce60640fc8a58139adc7 Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@erisindustries.com> Date: Mon, 20 Jun 2016 15:46:25 +0100 Subject: [PATCH] fixed self-vendoring issue --- glide.yaml | 3 +- manager/eris-mint/eris-mint.go | 250 +++++++++---------- rpc/test/helpers.go | 10 +- test/filters/filter_test.go | 5 +- test/mock/mock_web_api_test.go | 61 +++-- test/mock/pipe.go | 73 +++--- test/testdata/filters/testdata_filters.go | 11 +- test/testdata/testdata/testdata.go | 101 ++++---- test/transacting/transacting_test.go | 140 ----------- test/web_api/query_test.go | 138 ----------- test/web_api/shared.go | 19 -- test/web_api/web_api_test.go | 287 ---------------------- 12 files changed, 256 insertions(+), 842 deletions(-) delete mode 100644 test/transacting/transacting_test.go delete mode 100644 test/web_api/query_test.go delete mode 100644 test/web_api/shared.go delete mode 100644 test/web_api/web_api_test.go diff --git a/glide.yaml b/glide.yaml index e1730909..179439bd 100644 --- a/glide.yaml +++ b/glide.yaml @@ -4,7 +4,6 @@ import: - package: github.com/spf13/cobra - package: github.com/spf13/viper - package: github.com/tendermint/tendermint - version: 55ef4b225fb0aa5637a96d36a8c0d030a59dc21d - package: github.com/gin-gonic/gin - package: github.com/gorilla/websocket - package: github.com/naoina/toml @@ -15,3 +14,5 @@ import: - ripemd160 - package: gopkg.in/fatih/set.v0 - package: gopkg.in/tylerb/graceful.v1 +- package: golang.org/x/net/http2 + version: master diff --git a/manager/eris-mint/eris-mint.go b/manager/eris-mint/eris-mint.go index 4b351863..656493b7 100644 --- a/manager/eris-mint/eris-mint.go +++ b/manager/eris-mint/eris-mint.go @@ -17,22 +17,22 @@ package erismint import ( - "bytes" - "encoding/hex" - "fmt" - "sync" - - tendermint_events "github.com/tendermint/go-events" - client "github.com/tendermint/go-rpc/client" - wire "github.com/tendermint/go-wire" - ctypes "github.com/tendermint/tendermint/rpc/core/types" - tmsp "github.com/tendermint/tmsp/types" - - log "github.com/eris-ltd/eris-logger" - - manager_types "github.com/eris-ltd/eris-db/manager/types" - sm "github.com/eris-ltd/eris-db/manager/eris-mint/state" - types "github.com/eris-ltd/eris-db/txs" + "bytes" + "encoding/hex" + "fmt" + "sync" + + tendermint_events "github.com/tendermint/go-events" + client "github.com/tendermint/go-rpc/client" + wire "github.com/tendermint/go-wire" + ctypes "github.com/tendermint/tendermint/rpc/core/types" + tmsp "github.com/tendermint/tmsp/types" + + log "github.com/eris-ltd/eris-logger" + + sm "github.com/eris-ltd/eris-db/manager/eris-mint/state" + manager_types "github.com/eris-ltd/eris-db/manager/types" + types "github.com/eris-ltd/eris-db/txs" ) //-------------------------------------------------------------------------------- @@ -41,134 +41,134 @@ import ( // one for mempool, one for consensus. type ErisMint struct { - mtx sync.Mutex + mtx sync.Mutex - state *sm.State - cache *sm.BlockCache - checkCache *sm.BlockCache // for CheckTx (eg. so we get nonces right) + state *sm.State + cache *sm.BlockCache + checkCache *sm.BlockCache // for CheckTx (eg. so we get nonces right) - evc *tendermint_events.EventCache - evsw *tendermint_events.EventSwitch + evc *tendermint_events.EventCache + evsw *tendermint_events.EventSwitch - // client to the tendermint core rpc - client *client.ClientURI - host string // tendermint core endpoint + // client to the tendermint core rpc + client *client.ClientURI + host string // tendermint core endpoint - nTxs int // count txs in a block + nTxs int // count txs in a block } // NOTE [ben] Compiler check to ensure ErisMint successfully implements // eris-db/manager/types.Application var _ manager_types.Application = (*ErisMint)(nil) + // NOTE: [ben] also automatically implements tmsp.Application, // undesired but unharmful // var _ tmsp.Application = (*ErisMint)(nil) - func (app *ErisMint) GetState() *sm.State { - app.mtx.Lock() - defer app.mtx.Unlock() - return app.state.Copy() + app.mtx.Lock() + defer app.mtx.Unlock() + return app.state.Copy() } // TODO: this is used for call/callcode and to get nonces during mempool. // the former should work on last committed state only and the later should // be handled by the client, or a separate wallet-like nonce tracker thats not part of the app func (app *ErisMint) GetCheckCache() *sm.BlockCache { - return app.checkCache + return app.checkCache } func (app *ErisMint) SetHostAddress(host string) { - app.host = host - app.client = client.NewClientURI(host) //fmt.Sprintf("http://%s", host)) + app.host = host + app.client = client.NewClientURI(host) //fmt.Sprintf("http://%s", host)) } // Broadcast a tx to the tendermint core // NOTE: this assumes we know the address of core func (app *ErisMint) BroadcastTx(tx types.Tx) error { - buf := new(bytes.Buffer) - var n int - var err error - wire.WriteBinary(struct{ types.Tx }{tx}, buf, &n, &err) - if err != nil { - return err - } - - params := map[string]interface{}{ - "tx": hex.EncodeToString(buf.Bytes()), - } - - var result ctypes.TMResult - _, err = app.client.Call("broadcast_tx_sync", params, &result) - return err + buf := new(bytes.Buffer) + var n int + var err error + wire.WriteBinary(struct{ types.Tx }{tx}, buf, &n, &err) + if err != nil { + return err + } + + params := map[string]interface{}{ + "tx": hex.EncodeToString(buf.Bytes()), + } + + var result ctypes.TMResult + _, err = app.client.Call("broadcast_tx_sync", params, &result) + return err } func NewErisMint(s *sm.State, evsw *tendermint_events.EventSwitch) *ErisMint { - return &ErisMint{ - state: s, - cache: sm.NewBlockCache(s), - checkCache: sm.NewBlockCache(s), - evc: tendermint_events.NewEventCache(evsw), - evsw: evsw, - } + return &ErisMint{ + state: s, + cache: sm.NewBlockCache(s), + checkCache: sm.NewBlockCache(s), + evc: tendermint_events.NewEventCache(evsw), + evsw: evsw, + } } // Implements manager/types.Application func (app *ErisMint) Info() (info string) { - return "ErisDB" + return "ErisDB" } // Implements manager/types.Application func (app *ErisMint) SetOption(key string, value string) (log string) { - return "" + return "" } // Implements manager/types.Application func (app *ErisMint) AppendTx(txBytes []byte) (res tmsp.Result) { - app.nTxs += 1 - - // XXX: if we had tx ids we could cache the decoded txs on CheckTx - var n int - var err error - tx := new(types.Tx) - buf := bytes.NewBuffer(txBytes) - wire.ReadBinaryPtr(tx, buf, len(txBytes), &n, &err) - if err != nil { - return tmsp.NewError(tmsp.CodeType_EncodingError, fmt.Sprintf("Encoding error: %v", err)) - } - - log.Info("AppendTx", "tx", *tx) - - err = sm.ExecTx(app.cache, *tx, true, app.evc) - if err != nil { - return tmsp.NewError(tmsp.CodeType_InternalError, fmt.Sprintf("Internal error: %v", err)) - } - // TODO: need to return receipt so rpc.ResultBroadcastTx.Data (or Log) is the receipt - return tmsp.NewResultOK(nil, "Success") + app.nTxs += 1 + + // XXX: if we had tx ids we could cache the decoded txs on CheckTx + var n int + var err error + tx := new(types.Tx) + buf := bytes.NewBuffer(txBytes) + wire.ReadBinaryPtr(tx, buf, len(txBytes), &n, &err) + if err != nil { + return tmsp.NewError(tmsp.CodeType_EncodingError, fmt.Sprintf("Encoding error: %v", err)) + } + + log.Info("AppendTx", "tx", *tx) + + err = sm.ExecTx(app.cache, *tx, true, app.evc) + if err != nil { + return tmsp.NewError(tmsp.CodeType_InternalError, fmt.Sprintf("Internal error: %v", err)) + } + // TODO: need to return receipt so rpc.ResultBroadcastTx.Data (or Log) is the receipt + return tmsp.NewResultOK(nil, "Success") } // Implements manager/types.Application func (app *ErisMint) CheckTx(txBytes []byte) (res tmsp.Result) { - var n int - var err error - tx := new(types.Tx) - buf := bytes.NewBuffer(txBytes) - wire.ReadBinaryPtr(tx, buf, len(txBytes), &n, &err) - if err != nil { - return tmsp.NewError(tmsp.CodeType_EncodingError, fmt.Sprintf("Encoding error: %v", err)) - } - - log.Info("CheckTx", "tx", *tx) - - // TODO: make errors tmsp aware - err = sm.ExecTx(app.checkCache, *tx, false, nil) - if err != nil { - return tmsp.NewError(tmsp.CodeType_InternalError, fmt.Sprintf("Internal error: %v", err)) - } - - // TODO: need to return receipt so rpc.ResultBroadcastTx.Data (or Log) is the receipt - return tmsp.NewResultOK(nil, "Success") + var n int + var err error + tx := new(types.Tx) + buf := bytes.NewBuffer(txBytes) + wire.ReadBinaryPtr(tx, buf, len(txBytes), &n, &err) + if err != nil { + return tmsp.NewError(tmsp.CodeType_EncodingError, fmt.Sprintf("Encoding error: %v", err)) + } + + log.Info("CheckTx", "tx", *tx) + + // TODO: make errors tmsp aware + err = sm.ExecTx(app.checkCache, *tx, false, nil) + if err != nil { + return tmsp.NewError(tmsp.CodeType_InternalError, fmt.Sprintf("Internal error: %v", err)) + } + + // TODO: need to return receipt so rpc.ResultBroadcastTx.Data (or Log) is the receipt + return tmsp.NewResultOK(nil, "Success") } // Implements manager/types.Application @@ -176,36 +176,36 @@ func (app *ErisMint) CheckTx(txBytes []byte) (res tmsp.Result) { // NOTE: CheckTx/AppendTx must not run concurrently with Commit - // the mempool should run during AppendTxs, but lock for Commit and Update func (app *ErisMint) Commit() (res tmsp.Result) { - app.mtx.Lock() // the lock protects app.state - defer app.mtx.Unlock() - - app.state.LastBlockHeight += 1 - log.WithFields(log.Fields{ - "blockheight" : app.state.LastBlockHeight, - }).Info("Commit block") - - // sync the AppendTx cache - app.cache.Sync() - - // if there were any txs in the block, - // reset the check cache to the new height - if app.nTxs > 0 { - log.WithFields(log.Fields{ - "txs" : app.nTxs, - }).Info("Reset checkCache") - app.checkCache = sm.NewBlockCache(app.state) - } - app.nTxs = 0 - - // save state to disk - app.state.Save() - - // flush events to listeners (XXX: note issue with blocking) - app.evc.Flush() - - return tmsp.NewResultOK(app.state.Hash(), "Success") + app.mtx.Lock() // the lock protects app.state + defer app.mtx.Unlock() + + app.state.LastBlockHeight += 1 + log.WithFields(log.Fields{ + "blockheight": app.state.LastBlockHeight, + }).Info("Commit block") + + // sync the AppendTx cache + app.cache.Sync() + + // if there were any txs in the block, + // reset the check cache to the new height + if app.nTxs > 0 { + log.WithFields(log.Fields{ + "txs": app.nTxs, + }).Info("Reset checkCache") + app.checkCache = sm.NewBlockCache(app.state) + } + app.nTxs = 0 + + // save state to disk + app.state.Save() + + // flush events to listeners (XXX: note issue with blocking) + app.evc.Flush() + + return tmsp.NewResultOK(app.state.Hash(), "Success") } func (app *ErisMint) Query(query []byte) (res tmsp.Result) { - return tmsp.NewResultOK(nil, "Success") + return tmsp.NewResultOK(nil, "Success") } diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index 2dfb07af..11647e64 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -6,12 +6,12 @@ import ( "testing" acm "github.com/eris-ltd/eris-db/account" - edb "github.com/eris-ltd/eris-db/erisdb" - edbcli "github.com/eris-ltd/eris-db/rpc/client" - ctypes "github.com/eris-ltd/eris-db/rpc/core/types" + edb "github.com/eris-ltd/eris-db/core" + erismint "github.com/eris-ltd/eris-db/manager/eris-mint" sm "github.com/eris-ltd/eris-db/manager/eris-mint/state" stypes "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" - edbapp "github.com/eris-ltd/eris-db/tmsp" + edbcli "github.com/eris-ltd/eris-db/rpc/client" + ctypes "github.com/eris-ltd/eris-db/rpc/core/types" txs "github.com/eris-ltd/eris-db/txs" . "github.com/tendermint/go-common" @@ -105,7 +105,7 @@ func newNode(ready chan struct{}) { evsw := events.NewEventSwitch() evsw.Start() // create the app - app := edbapp.NewErisDBApp(state, evsw) + app := erismint.NewErisMint(state, evsw) // Create & start node privValidatorFile := config.GetString("priv_validator_file") diff --git a/test/filters/filter_test.go b/test/filters/filter_test.go index ba0905f2..e1b0edbb 100644 --- a/test/filters/filter_test.go +++ b/test/filters/filter_test.go @@ -2,10 +2,11 @@ package filters import ( "fmt" - "github.com/stretchr/testify/suite" - . "github.com/eris-ltd/eris-db/erisdb/pipe" "sync" "testing" + + . "github.com/eris-ltd/eris-db/manager/eris-mint" + "github.com/stretchr/testify/suite" ) const OBJECTS = 100 diff --git a/test/mock/mock_web_api_test.go b/test/mock/mock_web_api_test.go index a621833d..9b1aad9b 100644 --- a/test/mock/mock_web_api_test.go +++ b/test/mock/mock_web_api_test.go @@ -9,11 +9,10 @@ import ( "runtime" "testing" - // edb "github.com/eris-ltd/erisdb/erisdb" "github.com/eris-ltd/eris-db/account" "github.com/eris-ltd/eris-db/config" - edb "github.com/eris-ltd/eris-db/erisdb" - ep "github.com/eris-ltd/eris-db/erisdb/pipe" + core "github.com/eris-ltd/eris-db/core" + core_types "github.com/eris-ltd/eris-db/core/types" "github.com/eris-ltd/eris-db/rpc" "github.com/eris-ltd/eris-db/server" td "github.com/eris-ltd/eris-db/test/testdata/testdata" @@ -47,10 +46,10 @@ func (this *MockSuite) SetupSuite() { // Load the supporting objects. testData := td.LoadTestData() pipe := NewMockPipe(testData) - codec := &edb.TCodec{} - evtSubs := edb.NewEventSubscriptions(pipe.Events()) + codec := &core_types.TCodec{} + evtSubs := core.NewEventSubscriptions(pipe.Events()) // The server - restServer := edb.NewRestServer(codec, pipe, evtSubs) + restServer := core.NewRestServer(codec, pipe, evtSubs) sConf := config.DefaultServerConfig() sConf.Bind.Port = 31402 // Create a server process. @@ -60,7 +59,7 @@ func (this *MockSuite) SetupSuite() { panic(err) } this.serveProcess = proc - this.codec = edb.NewTCodec() + this.codec = core_types.NewTCodec() this.testData = testData this.sUrl = "http://localhost:31402" } @@ -75,7 +74,7 @@ func (this *MockSuite) TearDownSuite() { func (this *MockSuite) TestGetAccounts() { resp := this.get("/accounts") - ret := &ep.AccountList{} + ret := &core_types.AccountList{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetAccounts.Output) @@ -93,7 +92,7 @@ func (this *MockSuite) TestGetAccount() { func (this *MockSuite) TestGetStorage() { addr := hex.EncodeToString(this.testData.GetStorage.Input.Address) resp := this.get("/accounts/" + addr + "/storage") - ret := &ep.Storage{} + ret := &core_types.Storage{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetStorage.Output) @@ -103,7 +102,7 @@ func (this *MockSuite) TestGetStorageAt() { addr := hex.EncodeToString(this.testData.GetStorageAt.Input.Address) key := hex.EncodeToString(this.testData.GetStorageAt.Input.Key) resp := this.get("/accounts/" + addr + "/storage/" + key) - ret := &ep.StorageItem{} + ret := &core_types.StorageItem{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetStorageAt.Output) @@ -113,7 +112,7 @@ func (this *MockSuite) TestGetStorageAt() { func (this *MockSuite) TestGetBlockchainInfo() { resp := this.get("/blockchain") - ret := &ep.BlockchainInfo{} + ret := &core_types.BlockchainInfo{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetBlockchainInfo.Output) @@ -121,7 +120,7 @@ func (this *MockSuite) TestGetBlockchainInfo() { func (this *MockSuite) TestGetChainId() { resp := this.get("/blockchain/chain_id") - ret := &ep.ChainId{} + ret := &core_types.ChainId{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetChainId.Output) @@ -129,7 +128,7 @@ func (this *MockSuite) TestGetChainId() { func (this *MockSuite) TestGetGenesisHash() { resp := this.get("/blockchain/genesis_hash") - ret := &ep.GenesisHash{} + ret := &core_types.GenesisHash{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetGenesisHash.Output) @@ -137,7 +136,7 @@ func (this *MockSuite) TestGetGenesisHash() { func (this *MockSuite) TestLatestBlockHeight() { resp := this.get("/blockchain/latest_block_height") - ret := &ep.LatestBlockHeight{} + ret := &core_types.LatestBlockHeight{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetLatestBlockHeight.Output) @@ -145,7 +144,7 @@ func (this *MockSuite) TestLatestBlockHeight() { func (this *MockSuite) TestBlocks() { resp := this.get("/blockchain/blocks") - ret := &ep.Blocks{} + ret := &core_types.Blocks{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetBlocks.Output) @@ -155,7 +154,7 @@ func (this *MockSuite) TestBlocks() { func (this *MockSuite) TestGetConsensusState() { resp := this.get("/consensus") - ret := &ep.ConsensusState{} + ret := &core_types.ConsensusState{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) ret.StartTime = "" @@ -164,7 +163,7 @@ func (this *MockSuite) TestGetConsensusState() { func (this *MockSuite) TestGetValidators() { resp := this.get("/consensus/validators") - ret := &ep.ValidatorList{} + ret := &core_types.ValidatorList{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetValidators.Output) @@ -182,7 +181,7 @@ func (this *MockSuite) TestGetNameRegEntry() { func (this *MockSuite) TestGetNameRegEntries() { resp := this.get("/namereg") - ret := &ep.ResultListNames{} + ret := &core_types.ResultListNames{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetNameRegEntries.Output) @@ -192,7 +191,7 @@ func (this *MockSuite) TestGetNameRegEntries() { func (this *MockSuite) TestGetNetworkInfo() { resp := this.get("/network") - ret := &ep.NetworkInfo{} + ret := &core_types.NetworkInfo{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetNetworkInfo.Output) @@ -200,7 +199,7 @@ func (this *MockSuite) TestGetNetworkInfo() { func (this *MockSuite) TestGetClientVersion() { resp := this.get("/network/client_version") - ret := &ep.ClientVersion{} + ret := &core_types.ClientVersion{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetClientVersion.Output) @@ -208,7 +207,7 @@ func (this *MockSuite) TestGetClientVersion() { func (this *MockSuite) TestGetMoniker() { resp := this.get("/network/moniker") - ret := &ep.Moniker{} + ret := &core_types.Moniker{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetMoniker.Output) @@ -216,7 +215,7 @@ func (this *MockSuite) TestGetMoniker() { func (this *MockSuite) TestIsListening() { resp := this.get("/network/listening") - ret := &ep.Listening{} + ret := &core_types.Listening{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.IsListening.Output) @@ -224,7 +223,7 @@ func (this *MockSuite) TestIsListening() { func (this *MockSuite) TestGetListeners() { resp := this.get("/network/listeners") - ret := &ep.Listeners{} + ret := &core_types.Listeners{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetListeners.Output) @@ -232,7 +231,7 @@ func (this *MockSuite) TestGetListeners() { func (this *MockSuite) TestGetPeers() { resp := this.get("/network/peers") - ret := []*ep.Peer{} + ret := []*core_types.Peer{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetPeers.Output) @@ -242,7 +241,7 @@ func (this *MockSuite) TestGetPeers() { func (this *MockSuite) TestGetPeer() { addr := this.testData.GetPeer.Input.Address resp := this.get("/network/peer/" + addr) - ret := []*ep.Peer{} + ret := []*core_types.Peer{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetPeers.Output) @@ -253,7 +252,7 @@ func (this *MockSuite) TestGetPeer() { func (this *MockSuite) TestTransactCreate() { resp := this.postJson("/unsafe/txpool", this.testData.TransactCreate.Input) - ret := &ep.Receipt{} + ret := &core_types.Receipt{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.TransactCreate.Output) @@ -261,7 +260,7 @@ func (this *MockSuite) TestTransactCreate() { func (this *MockSuite) TestTransact() { resp := this.postJson("/unsafe/txpool", this.testData.Transact.Input) - ret := &ep.Receipt{} + ret := &core_types.Receipt{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.Transact.Output) @@ -269,7 +268,7 @@ func (this *MockSuite) TestTransact() { func (this *MockSuite) TestTransactNameReg() { resp := this.postJson("/unsafe/namereg/txpool", this.testData.TransactNameReg.Input) - ret := &ep.Receipt{} + ret := &core_types.Receipt{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.TransactNameReg.Output) @@ -277,7 +276,7 @@ func (this *MockSuite) TestTransactNameReg() { func (this *MockSuite) TestGetUnconfirmedTxs() { resp := this.get("/txpool") - ret := &ep.UnconfirmedTxs{} + ret := &core_types.UnconfirmedTxs{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetUnconfirmedTxs.Output) @@ -285,7 +284,7 @@ func (this *MockSuite) TestGetUnconfirmedTxs() { func (this *MockSuite) TestCallCode() { resp := this.postJson("/codecalls", this.testData.CallCode.Input) - ret := &ep.Call{} + ret := &core_types.Call{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.CallCode.Output) @@ -293,7 +292,7 @@ func (this *MockSuite) TestCallCode() { func (this *MockSuite) TestCall() { resp := this.postJson("/calls", this.testData.Call.Input) - ret := &ep.Call{} + ret := &core_types.Call{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.CallCode.Output) diff --git a/test/mock/pipe.go b/test/mock/pipe.go index dfc032a4..b8e7e580 100644 --- a/test/mock/pipe.go +++ b/test/mock/pipe.go @@ -2,28 +2,27 @@ package mock import ( "github.com/eris-ltd/eris-db/account" - ep "github.com/eris-ltd/eris-db/erisdb/pipe" + core_types "github.com/eris-ltd/eris-db/core/types" td "github.com/eris-ltd/eris-db/test/testdata/testdata" types "github.com/eris-ltd/eris-db/txs" - "github.com/tendermint/go-events" mintTypes "github.com/tendermint/tendermint/types" ) // Base struct. type MockPipe struct { testData *td.TestData - accounts ep.Accounts - blockchain ep.Blockchain - consensus ep.Consensus - events ep.EventEmitter - namereg ep.NameReg - net ep.Net - transactor ep.Transactor + accounts core_types.Accounts + blockchain core_types.Blockchain + consensus core_types.Consensus + events core_types.EventEmitter + namereg core_types.NameReg + net core_types.Net + transactor core_types.Transactor } // Create a new mock tendermint pipe. -func NewMockPipe(td *td.TestData) ep.Pipe { +func NewMockPipe(td *td.TestData) core_types.Pipe { accounts := &accounts{td} blockchain := &blockchain{td} consensus := &consensus{td} @@ -44,35 +43,35 @@ func NewMockPipe(td *td.TestData) ep.Pipe { } // Create a mock pipe with default mock data. -func NewDefaultMockPipe() ep.Pipe { +func NewDefaultMockPipe() core_types.Pipe { return NewMockPipe(td.LoadTestData()) } -func (this *MockPipe) Accounts() ep.Accounts { +func (this *MockPipe) Accounts() core_types.Accounts { return this.accounts } -func (this *MockPipe) Blockchain() ep.Blockchain { +func (this *MockPipe) Blockchain() core_types.Blockchain { return this.blockchain } -func (this *MockPipe) Consensus() ep.Consensus { +func (this *MockPipe) Consensus() core_types.Consensus { return this.consensus } -func (this *MockPipe) Events() ep.EventEmitter { +func (this *MockPipe) Events() core_types.EventEmitter { return this.events } -func (this *MockPipe) NameReg() ep.NameReg { +func (this *MockPipe) NameReg() core_types.NameReg { return this.namereg } -func (this *MockPipe) Net() ep.Net { +func (this *MockPipe) Net() core_types.Net { return this.net } -func (this *MockPipe) Transactor() ep.Transactor { +func (this *MockPipe) Transactor() core_types.Transactor { return this.transactor } @@ -91,7 +90,7 @@ func (this *accounts) GenPrivAccountFromKey(key []byte) (*account.PrivAccount, e return this.testData.GenPrivAccount.Output, nil } -func (this *accounts) Accounts([]*ep.FilterData) (*ep.AccountList, error) { +func (this *accounts) Accounts([]*core_types.FilterData) (*core_types.AccountList, error) { return this.testData.GetAccounts.Output, nil } @@ -99,11 +98,11 @@ func (this *accounts) Account(address []byte) (*account.Account, error) { return this.testData.GetAccount.Output, nil } -func (this *accounts) Storage(address []byte) (*ep.Storage, error) { +func (this *accounts) Storage(address []byte) (*core_types.Storage, error) { return this.testData.GetStorage.Output, nil } -func (this *accounts) StorageAt(address, key []byte) (*ep.StorageItem, error) { +func (this *accounts) StorageAt(address, key []byte) (*core_types.StorageItem, error) { return this.testData.GetStorageAt.Output, nil } @@ -112,7 +111,7 @@ type blockchain struct { testData *td.TestData } -func (this *blockchain) Info() (*ep.BlockchainInfo, error) { +func (this *blockchain) Info() (*core_types.BlockchainInfo, error) { return this.testData.GetBlockchainInfo.Output, nil } @@ -132,7 +131,7 @@ func (this *blockchain) LatestBlock() (*mintTypes.Block, error) { return this.testData.GetLatestBlock.Output, nil } -func (this *blockchain) Blocks([]*ep.FilterData) (*ep.Blocks, error) { +func (this *blockchain) Blocks([]*core_types.FilterData) (*core_types.Blocks, error) { return this.testData.GetBlocks.Output, nil } @@ -145,11 +144,11 @@ type consensus struct { testData *td.TestData } -func (this *consensus) State() (*ep.ConsensusState, error) { +func (this *consensus) State() (*core_types.ConsensusState, error) { return this.testData.GetConsensusState.Output, nil } -func (this *consensus) Validators() (*ep.ValidatorList, error) { +func (this *consensus) Validators() (*core_types.ValidatorList, error) { return this.testData.GetValidators.Output, nil } @@ -175,7 +174,7 @@ func (this *namereg) Entry(key string) (*types.NameRegEntry, error) { return this.testData.GetNameRegEntry.Output, nil } -func (this *namereg) Entries(filters []*ep.FilterData) (*ep.ResultListNames, error) { +func (this *namereg) Entries(filters []*core_types.FilterData) (*core_types.ResultListNames, error) { return this.testData.GetNameRegEntries.Output, nil } @@ -184,7 +183,7 @@ type net struct { testData *td.TestData } -func (this *net) Info() (*ep.NetworkInfo, error) { +func (this *net) Info() (*core_types.NetworkInfo, error) { return this.testData.GetNetworkInfo.Output, nil } @@ -204,11 +203,11 @@ func (this *net) Listeners() ([]string, error) { return this.testData.GetListeners.Output.Listeners, nil } -func (this *net) Peers() ([]*ep.Peer, error) { +func (this *net) Peers() ([]*core_types.Peer, error) { return this.testData.GetPeers.Output, nil } -func (this *net) Peer(address string) (*ep.Peer, error) { +func (this *net) Peer(address string) (*core_types.Peer, error) { // return this.testData.GetPeer.Output, nil return nil, nil } @@ -218,23 +217,23 @@ type transactor struct { testData *td.TestData } -func (this *transactor) Call(fromAddress, toAddress, data []byte) (*ep.Call, error) { +func (this *transactor) Call(fromAddress, toAddress, data []byte) (*core_types.Call, error) { return this.testData.Call.Output, nil } -func (this *transactor) CallCode(from, code, data []byte) (*ep.Call, error) { +func (this *transactor) CallCode(from, code, data []byte) (*core_types.Call, error) { return this.testData.CallCode.Output, nil } -func (this *transactor) BroadcastTx(tx types.Tx) (*ep.Receipt, error) { +func (this *transactor) BroadcastTx(tx types.Tx) (*core_types.Receipt, error) { return nil, nil } -func (this *transactor) UnconfirmedTxs() (*ep.UnconfirmedTxs, error) { +func (this *transactor) UnconfirmedTxs() (*core_types.UnconfirmedTxs, error) { return this.testData.GetUnconfirmedTxs.Output, nil } -func (this *transactor) Transact(privKey, address, data []byte, gasLimit, fee int64) (*ep.Receipt, error) { +func (this *transactor) Transact(privKey, address, data []byte, gasLimit, fee int64) (*core_types.Receipt, error) { if address == nil || len(address) == 0 { return this.testData.TransactCreate.Output, nil } @@ -245,15 +244,15 @@ func (this *transactor) TransactAndHold(privKey, address, data []byte, gasLimit, return nil, nil } -func (this *transactor) Send(privKey, toAddress []byte, amount int64) (*ep.Receipt, error) { +func (this *transactor) Send(privKey, toAddress []byte, amount int64) (*core_types.Receipt, error) { return nil, nil } -func (this *transactor) SendAndHold(privKey, toAddress []byte, amount int64) (*ep.Receipt, error) { +func (this *transactor) SendAndHold(privKey, toAddress []byte, amount int64) (*core_types.Receipt, error) { return nil, nil } -func (this *transactor) TransactNameReg(privKey []byte, name, data string, amount, fee int64) (*ep.Receipt, error) { +func (this *transactor) TransactNameReg(privKey []byte, name, data string, amount, fee int64) (*core_types.Receipt, error) { return this.testData.TransactNameReg.Output, nil } diff --git a/test/testdata/filters/testdata_filters.go b/test/testdata/filters/testdata_filters.go index 4e0e67ab..d6585986 100644 --- a/test/testdata/filters/testdata_filters.go +++ b/test/testdata/filters/testdata_filters.go @@ -1,8 +1,7 @@ package filters import ( - edb "github.com/eris-ltd/eris-db/erisdb" - ep "github.com/eris-ltd/eris-db/erisdb/pipe" + core_types "github.com/eris-ltd/eris-db/core/types" stypes "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" "github.com/tendermint/tendermint/types" @@ -151,7 +150,7 @@ var testDataJson = `{ "set": 16383 }, "roles": [ - + ] } }, @@ -277,8 +276,8 @@ type ( } GetAccountData struct { - Input []*ep.FilterData `json:"input"` - Output *ep.AccountList `json:"output"` + Input []*core_types.FilterData `json:"input"` + Output *core_types.AccountList `json:"output"` } TestData struct { @@ -290,7 +289,7 @@ type ( ) func LoadTestData() *TestData { - codec := edb.NewTCodec() + codec := core_types.NewTCodec() testData := &TestData{} err := codec.DecodeBytes(testData, []byte(testDataJson)) if err != nil { diff --git a/test/testdata/testdata/testdata.go b/test/testdata/testdata/testdata.go index d90b0596..6abff9f7 100644 --- a/test/testdata/testdata/testdata.go +++ b/test/testdata/testdata/testdata.go @@ -2,12 +2,11 @@ package testdata import ( "github.com/eris-ltd/eris-db/account" - edb "github.com/eris-ltd/eris-db/erisdb" - ep "github.com/eris-ltd/eris-db/erisdb/pipe" + core "github.com/eris-ltd/eris-db/core" + core_types "github.com/eris-ltd/eris-db/core/types" stypes "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" types "github.com/eris-ltd/eris-db/txs" - "github.com/tendermint/go-wire" mintTypes "github.com/tendermint/tendermint/types" ) @@ -511,23 +510,23 @@ type ( } GetAccountData struct { - Input *edb.AddressParam `json:"input"` - Output *account.Account `json:"output"` + Input *core.AddressParam `json:"input"` + Output *account.Account `json:"output"` } GetAccountsData struct { - Input *edb.AccountsParam `json:"input"` - Output *ep.AccountList `json:"output"` + Input *core.AccountsParam `json:"input"` + Output *core_types.AccountList `json:"output"` } GetStorageData struct { - Input *edb.AddressParam `json:"input"` - Output *ep.Storage `json:"output"` + Input *core.AddressParam `json:"input"` + Output *core_types.Storage `json:"output"` } GetStorageAtData struct { - Input *edb.StorageAtParam `json:"input"` - Output *ep.StorageItem `json:"output"` + Input *core.StorageAtParam `json:"input"` + Output *core_types.StorageItem `json:"output"` } GenPrivAccountData struct { @@ -535,19 +534,19 @@ type ( } GetBlockchainInfoData struct { - Output *ep.BlockchainInfo `json:"output"` + Output *core_types.BlockchainInfo `json:"output"` } GetChainIdData struct { - Output *ep.ChainId `json:"output"` + Output *core_types.ChainId `json:"output"` } GetGenesisHashData struct { - Output *ep.GenesisHash `json:"output"` + Output *core_types.GenesisHash `json:"output"` } GetLatestBlockHeightData struct { - Output *ep.LatestBlockHeight `json:"output"` + Output *core_types.LatestBlockHeight `json:"output"` } GetLatestBlockData struct { @@ -555,105 +554,105 @@ type ( } GetBlockData struct { - Input *edb.HeightParam `json:"input"` - Output *mintTypes.Block `json:"output"` + Input *core.HeightParam `json:"input"` + Output *mintTypes.Block `json:"output"` } GetBlocksData struct { - Input *edb.BlocksParam `json:"input"` - Output *ep.Blocks `json:"output"` + Input *core.BlocksParam `json:"input"` + Output *core_types.Blocks `json:"output"` } GetConsensusStateData struct { - Output *ep.ConsensusState `json:"output"` + Output *core_types.ConsensusState `json:"output"` } GetValidatorsData struct { - Output *ep.ValidatorList `json:"output"` + Output *core_types.ValidatorList `json:"output"` } GetNetworkInfoData struct { - Output *ep.NetworkInfo `json:"output"` + Output *core_types.NetworkInfo `json:"output"` } GetClientVersionData struct { - Output *ep.ClientVersion `json:"output"` + Output *core_types.ClientVersion `json:"output"` } GetMonikerData struct { - Output *ep.Moniker `json:"output"` + Output *core_types.Moniker `json:"output"` } IsListeningData struct { - Output *ep.Listening `json:"output"` + Output *core_types.Listening `json:"output"` } GetListenersData struct { - Output *ep.Listeners `json:"output"` + Output *core_types.Listeners `json:"output"` } GetPeersData struct { - Output []*ep.Peer `json:"output"` + Output []*core_types.Peer `json:"output"` } GetPeerData struct { - Input *edb.PeerParam `json:"input"` - Output *ep.Peer `json:"output"` + Input *core.PeerParam `json:"input"` + Output *core_types.Peer `json:"output"` } TransactData struct { - Input *edb.TransactParam `json:"input"` - Output *ep.Receipt `json:"output"` + Input *core.TransactParam `json:"input"` + Output *core_types.Receipt `json:"output"` } TransactCreateData struct { - Input *edb.TransactParam `json:"input"` - Output *ep.Receipt `json:"output"` + Input *core.TransactParam `json:"input"` + Output *core_types.Receipt `json:"output"` } GetUnconfirmedTxsData struct { - Output *ep.UnconfirmedTxs `json:"output"` + Output *core_types.UnconfirmedTxs `json:"output"` } CallCodeData struct { - Input *edb.CallCodeParam `json:"input"` - Output *ep.Call `json:"output"` + Input *core.CallCodeParam `json:"input"` + Output *core_types.Call `json:"output"` } CallData struct { - Input *edb.CallParam `json:"input"` - Output *ep.Call `json:"output"` + Input *core.CallParam `json:"input"` + Output *core_types.Call `json:"output"` } EventSubscribeData struct { - Input *edb.EventIdParam `json:"input"` - Output *ep.EventSub `json:"output"` + Input *core.EventIdParam `json:"input"` + Output *core_types.EventSub `json:"output"` } EventUnsubscribeData struct { - Input *edb.SubIdParam `json:"input"` - Output *ep.EventUnsub `json:"output"` + Input *core.SubIdParam `json:"input"` + Output *core_types.EventUnsub `json:"output"` } TransactNameRegData struct { - Input *edb.TransactNameRegParam `json:"input"` - Output *ep.Receipt `json:"output"` + Input *core.TransactNameRegParam `json:"input"` + Output *core_types.Receipt `json:"output"` } GetNameRegEntryData struct { - Input *edb.NameRegEntryParam `json:"input"` - Output *types.NameRegEntry `json:"output"` + Input *core.NameRegEntryParam `json:"input"` + Output *types.NameRegEntry `json:"output"` } GetNameRegEntriesData struct { - Input *edb.FilterListParam `json:"input"` - Output *ep.ResultListNames `json:"output"` + Input *core.FilterListParam `json:"input"` + Output *core_types.ResultListNames `json:"output"` } /* EventPollData struct { - Input *edb.SubIdParam `json:"input"` - Output *ep.PollResponse `json:"output"` + Input *core.SubIdParam `json:"input"` + Output *core_types.PollResponse `json:"output"` } */ @@ -696,7 +695,7 @@ type ( func LoadTestData() *TestData { var err error - //codec := edb.NewTCodec() + //codec := core_types.NewTCodec() testData := TestData{} testDataI := wire.ReadJSON(testData, []byte(testDataJson), &err) /*err := codec.DecodeBytes(testData, []byte(testDataJson)) diff --git a/test/transacting/transacting_test.go b/test/transacting/transacting_test.go deleted file mode 100644 index 62cf84c9..00000000 --- a/test/transacting/transacting_test.go +++ /dev/null @@ -1,140 +0,0 @@ -package transacting - -// Basic imports -import ( - "bytes" - "fmt" - "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/stretchr/testify/suite" - // "github.com/tendermint/tendermint/types" - edb "github.com/eris-ltd/eris-db/erisdb" - ess "github.com/eris-ltd/eris-db/erisdb/erisdbss" - // ep "github.com/eris-ltd/eris-db/erisdb/pipe" - "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/gin-gonic/gin" - "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/log15" - "github.com/eris-ltd/eris-db/rpc" - "github.com/eris-ltd/eris-db/server" - td "github.com/eris-ltd/eris-db/test/testdata/testdata" - "io/ioutil" - "net/http" - "os" - "path" - "runtime" - "testing" -) - -func init() { - runtime.GOMAXPROCS(runtime.NumCPU()) - log15.Root().SetHandler(log15.LvlFilterHandler( - log15.LvlInfo, - log15.StreamHandler(os.Stdout, log15.TerminalFormat()), - )) - gin.SetMode(gin.ReleaseMode) -} - -const ( - TX_URL = "http://localhost:31405/server" - CONTRACT_CODE = "60606040525b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b609480603e6000396000f30060606040523615600d57600d565b60685b6000600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050805033600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b90565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f3" -) - -func getCreateInput(privKey [64]byte) *edb.TransactParam { - tp := &edb.TransactParam{} - tp.PrivKey = privKey[:] - tp.Address = nil - tp.Data = []byte(CONTRACT_CODE) - tp.GasLimit = 100000 - tp.Fee = 0 - return tp -} - -type TxSuite struct { - suite.Suite - baseDir string - serveProcess *server.ServeProcess - codec rpc.Codec - sUrl string - testData *td.TestData -} - -func (this *TxSuite) SetupSuite() { - baseDir := path.Join(os.TempDir(), "/.edbservers") - ss := ess.NewServerServer(baseDir) - cfg := server.DefaultServerConfig() - cfg.Bind.Port = uint16(31405) - proc := server.NewServeProcess(cfg, ss) - err := proc.Start() - if err != nil { - panic(err) - } - this.serveProcess = proc - testData := td.LoadTestData() - this.codec = edb.NewTCodec() - - requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, 30} - rBts, _ := this.codec.EncodeBytes(requestData) - resp, _ := http.Post(TX_URL, "application/json", bytes.NewBuffer(rBts)) - if resp.StatusCode != 200 { - bts, _ := ioutil.ReadAll(resp.Body) - fmt.Println("ERROR GETTING SS ADDRESS: " + string(bts)) - fmt.Printf("%v\n", resp) - panic(fmt.Errorf(string(bts))) - } - rd := &ess.ResponseData{} - err2 := this.codec.Decode(rd, resp.Body) - if err2 != nil { - panic(err2) - } - fmt.Println("Received Port: " + rd.Port) - this.sUrl = "http://localhost:" + rd.Port - fmt.Println("URL: " + this.sUrl) - this.testData = testData -} - -func (this *TxSuite) TearDownSuite() { - sec := this.serveProcess.StopEventChannel() - this.serveProcess.Stop(0) - <-sec -} - -// ********************************************* Tests ********************************************* - -// TODO less duplication. -func (this *TxSuite) Test_A0_Tx_Create() { - input := getCreateInput([64]byte(this.testData.ChainData.PrivValidator.PrivKey)) - // FIXME: fails for ?hold=true - resp := this.postJson("/unsafe/txpool?hold=false", input) - bts, err := ioutil.ReadAll(resp.Body) - if err != nil { - panic(err) - } else { - fmt.Printf("%s\n", string(bts)) - } - //ret := &types.EventMsgCall{} - // errD := this.codec.Decode(ret, resp.Body) - //this.NoError(errD) - //json, _ := this.codec.EncodeBytes(ret) - //fmt.Printf("%s\n", string(json)) -} - -// ********************************************* Utilities ********************************************* - -func (this *TxSuite) get(endpoint string) *http.Response { - resp, errG := http.Get(this.sUrl + endpoint) - this.NoError(errG) - this.Equal(200, resp.StatusCode) - return resp -} - -func (this *TxSuite) postJson(endpoint string, v interface{}) *http.Response { - bts, errE := this.codec.EncodeBytes(v) - this.NoError(errE) - resp, errP := http.Post(this.sUrl+endpoint, "application/json", bytes.NewBuffer(bts)) - this.NoError(errP) - this.Equal(200, resp.StatusCode) - return resp -} - -// ********************************************* Entrypoint ********************************************* - -func TestQuerySuite(t *testing.T) { - suite.Run(t, &TxSuite{}) -} diff --git a/test/web_api/query_test.go b/test/web_api/query_test.go deleted file mode 100644 index 1c094b2d..00000000 --- a/test/web_api/query_test.go +++ /dev/null @@ -1,138 +0,0 @@ -package web_api - -// Basic imports -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "os" - "path" - "testing" - - "github.com/eris-ltd/eris-db/config" - edb "github.com/eris-ltd/eris-db/erisdb" - ess "github.com/eris-ltd/eris-db/erisdb/erisdbss" - ep "github.com/eris-ltd/eris-db/erisdb/pipe" - "github.com/eris-ltd/eris-db/rpc" - "github.com/eris-ltd/eris-db/server" - fd "github.com/eris-ltd/eris-db/test/testdata/filters" - "github.com/stretchr/testify/suite" -) - -const QS_URL = "http://localhost:31403/server" - -type QuerySuite struct { - suite.Suite - baseDir string - serveProcess *server.ServeProcess - codec rpc.Codec - sUrl string - testData *fd.TestData -} - -func (this *QuerySuite) SetupSuite() { - baseDir := path.Join(os.TempDir(), "/.edbservers") - ss := ess.NewServerServer(baseDir) - cfg := config.DefaultServerConfig() - cfg.Bind.Port = uint16(31403) - proc := server.NewServeProcess(&cfg, ss) - err := proc.Start() - if err != nil { - panic(err) - } - this.serveProcess = proc - testData := fd.LoadTestData() - this.codec = edb.NewTCodec() - - requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, SERVER_DURATION} - rBts, _ := this.codec.EncodeBytes(requestData) - resp, _ := http.Post(QS_URL, "application/json", bytes.NewBuffer(rBts)) - if resp.StatusCode != 200 { - bts, _ := ioutil.ReadAll(resp.Body) - fmt.Println("ERROR GETTING SS ADDRESS: " + string(bts)) - fmt.Printf("%v\n", resp) - panic(fmt.Errorf(string(bts))) - } - rd := &ess.ResponseData{} - err2 := this.codec.Decode(rd, resp.Body) - if err2 != nil { - panic(err2) - } - fmt.Println("Received Port: " + rd.Port) - this.sUrl = "http://localhost:" + rd.Port - fmt.Println("URL: " + this.sUrl) - this.testData = testData -} - -func (this *QuerySuite) TearDownSuite() { - sec := this.serveProcess.StopEventChannel() - this.serveProcess.Stop(0) - <-sec -} - -// ********************************************* Tests ********************************************* - -// TODO less duplication. -func (this *QuerySuite) Test_Accounts0() { - fd := this.testData.GetAccounts0.Input - resp := this.get("/accounts?" + generateQuery(fd)) - ret := &ep.AccountList{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(this.testData.GetAccounts0.Output, ret) -} - -func (this *QuerySuite) Test_Accounts1() { - fd := this.testData.GetAccounts1.Input - resp := this.get("/accounts?" + generateQuery(fd)) - ret := &ep.AccountList{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(this.testData.GetAccounts1.Output, ret) -} - -func (this *QuerySuite) Test_Accounts2() { - fd := this.testData.GetAccounts2.Input - resp := this.get("/accounts?" + generateQuery(fd)) - ret := &ep.AccountList{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(this.testData.GetAccounts2.Output, ret) -} - -// ********************************************* Utilities ********************************************* - -func (this *QuerySuite) get(endpoint string) *http.Response { - resp, errG := http.Get(this.sUrl + endpoint) - this.NoError(errG) - this.Equal(200, resp.StatusCode) - return resp -} - -func (this *QuerySuite) postJson(endpoint string, v interface{}) *http.Response { - bts, errE := this.codec.EncodeBytes(v) - this.NoError(errE) - resp, errP := http.Post(this.sUrl+endpoint, "application/json", bytes.NewBuffer(bts)) - this.NoError(errP) - this.Equal(200, resp.StatusCode) - return resp -} - -func generateQuery(fda []*ep.FilterData) string { - query := "q=" - for i := 0; i < len(fda); i++ { - fd := fda[i] - query += fd.Field + ":" + fd.Op + fd.Value - if i != len(fda)-1 { - query += "+" - } - } - return query -} - -// ********************************************* Entrypoint ********************************************* - -func TestQuerySuite(t *testing.T) { - suite.Run(t, &QuerySuite{}) -} diff --git a/test/web_api/shared.go b/test/web_api/shared.go deleted file mode 100644 index 406fbbcd..00000000 --- a/test/web_api/shared.go +++ /dev/null @@ -1,19 +0,0 @@ -package web_api - -import ( - "github.com/gin-gonic/gin" - "github.com/tendermint/log15" - "os" - "runtime" -) - -const SERVER_DURATION = 10 - -func init() { - runtime.GOMAXPROCS(runtime.NumCPU()) - log15.Root().SetHandler(log15.LvlFilterHandler( - log15.LvlInfo, - log15.StreamHandler(os.Stdout, log15.TerminalFormat()), - )) - gin.SetMode(gin.ReleaseMode) -} diff --git a/test/web_api/web_api_test.go b/test/web_api/web_api_test.go deleted file mode 100644 index c1eaf57c..00000000 --- a/test/web_api/web_api_test.go +++ /dev/null @@ -1,287 +0,0 @@ -package web_api - -// Basic imports -import ( - "bytes" - "encoding/hex" - "fmt" - // edb "github.com/eris-ltd/erisdb/erisdb" - "io/ioutil" - "net/http" - "os" - "path" - "testing" - - "github.com/eris-ltd/eris-db/account" - "github.com/eris-ltd/eris-db/config" - edb "github.com/eris-ltd/eris-db/erisdb" - ess "github.com/eris-ltd/eris-db/erisdb/erisdbss" - ep "github.com/eris-ltd/eris-db/erisdb/pipe" - "github.com/eris-ltd/eris-db/rpc" - "github.com/eris-ltd/eris-db/server" - td "github.com/eris-ltd/eris-db/test/testdata/testdata" - "github.com/gin-gonic/gin" - "github.com/stretchr/testify/suite" -) - -const WAPIS_URL = "http://localhost:31404/server" - -type WebApiSuite struct { - suite.Suite - baseDir string - serveProcess *server.ServeProcess - codec rpc.Codec - sUrl string - testData *td.TestData -} - -func (this *WebApiSuite) SetupSuite() { - gin.SetMode(gin.ReleaseMode) - baseDir := path.Join(os.TempDir(), "/.edbservers") - ss := ess.NewServerServer(baseDir) - cfg := config.DefaultServerConfig() - cfg.Bind.Port = uint16(31404) - proc := server.NewServeProcess(&cfg, ss) - err := proc.Start() - if err != nil { - panic(err) - } - this.serveProcess = proc - testData := td.LoadTestData() - this.codec = edb.NewTCodec() - - requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, SERVER_DURATION} - rBts, _ := this.codec.EncodeBytes(requestData) - resp, _ := http.Post(WAPIS_URL, "application/json", bytes.NewBuffer(rBts)) - rd := &ess.ResponseData{} - err2 := this.codec.Decode(rd, resp.Body) - if err2 != nil { - panic(err2) - } - fmt.Println("Received Port: " + rd.Port) - this.sUrl = "http://localhost:" + rd.Port - this.testData = testData -} - -func (this *WebApiSuite) TearDownSuite() { - sec := this.serveProcess.StopEventChannel() - this.serveProcess.Stop(0) - <-sec -} - -// ********************************************* Consensus ********************************************* -// TODO -/* -func (this *WebApiSuite) Test_A0_ConsensusState() { - resp := this.get("/consensus") - ret := &ep.ConsensusState{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - ret.StartTime = "" - this.Equal(ret, this.testData.GetConsensusState.Output) -} - -func (this *WebApiSuite) Test_A1_Validators() { - resp := this.get("/consensus/validators") - ret := &ep.ValidatorList{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetValidators.Output) -} - -// ********************************************* Network ********************************************* - -func (this *WebApiSuite) Test_B0_NetworkInfo() { - resp := this.get("/network") - ret := &ep.NetworkInfo{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetNetworkInfo.Output) -} - -func (this *WebApiSuite) Test_B1_ClientVersion() { - resp := this.get("/network/client_version") - ret := &ep.ClientVersion{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetClientVersion.Output) -} - -func (this *WebApiSuite) Test_B2_Moniker() { - resp := this.get("/network/moniker") - ret := &ep.Moniker{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetMoniker.Output) -} - -func (this *WebApiSuite) Test_B3_Listening() { - resp := this.get("/network/listening") - ret := &ep.Listening{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.IsListening.Output) -} - -func (this *WebApiSuite) Test_B4_Listeners() { - resp := this.get("/network/listeners") - ret := &ep.Listeners{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetListeners.Output) -} - -func (this *WebApiSuite) Test_B5_Peers() { - resp := this.get("/network/peers") - ret := []*ep.Peer{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetPeers.Output) -} -*/ - -// ********************************************* Transactions ********************************************* -// TODO -/* -func (this *WebApiSuite) Test_C0_TxCreate() { - resp := this.postJson("/unsafe/txpool", this.testData.TransactCreate.Input) - ret := &ep.Receipt{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.TransactCreate.Output) -} - -func (this *WebApiSuite) Test_C1_Tx() { - resp := this.postJson("/unsafe/txpool", this.testData.Transact.Input) - ret := &ep.Receipt{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.Transact.Output) -} - -func (this *WebApiSuite) Test_C2_UnconfirmedTxs() { - resp := this.get("/txpool") - ret := &ep.UnconfirmedTxs{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetUnconfirmedTxs.Output) -} - -func (this *WebApiSuite) Test_C3_CallCode() { - resp := this.postJson("/codecalls", this.testData.CallCode.Input) - ret := &ep.Call{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.CallCode.Output) -} -*/ -// ********************************************* Accounts ********************************************* - -func (this *WebApiSuite) Test_D0_GetAccounts() { - resp := this.get("/accounts") - ret := &ep.AccountList{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetAccounts.Output) -} - -func (this *WebApiSuite) Test_D1_GetAccount() { - addr := hex.EncodeToString(this.testData.GetAccount.Input.Address) - resp := this.get("/accounts/" + addr) - ret := &account.Account{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetAccount.Output) -} - -func (this *WebApiSuite) Test_D2_GetStorage() { - addr := hex.EncodeToString(this.testData.GetStorage.Input.Address) - resp := this.get("/accounts/" + addr + "/storage") - ret := &ep.Storage{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetStorage.Output) -} - -func (this *WebApiSuite) Test_D3_GetStorageAt() { - addr := hex.EncodeToString(this.testData.GetStorageAt.Input.Address) - key := hex.EncodeToString(this.testData.GetStorageAt.Input.Key) - resp := this.get("/accounts/" + addr + "/storage/" + key) - ret := &ep.StorageItem{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetStorageAt.Output) -} - -// ********************************************* Blockchain ********************************************* -// TODO -/* - -func (this *WebApiSuite) Test_E0_GetBlockchainInfo() { - resp := this.get("/blockchain") - ret := &ep.BlockchainInfo{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetBlockchainInfo.Output) -} - -func (this *WebApiSuite) Test_E1_GetChainId() { - resp := this.get("/blockchain/chain_id") - ret := &ep.ChainId{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetChainId.Output) -} - -func (this *WebApiSuite) Test_E2_GetGenesisHash() { - resp := this.get("/blockchain/genesis_hash") - ret := &ep.GenesisHash{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetGenesisHash.Output) -} - -func (this *WebApiSuite) Test_E3_GetLatestBlockHeight() { - resp := this.get("/blockchain/latest_block_height") - ret := &ep.LatestBlockHeight{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetLatestBlockHeight.Output) -} - -func (this *WebApiSuite) Test_E4_GetBlocks() { - resp := this.get("/blockchain/blocks") - ret := &ep.Blocks{} - errD := this.codec.Decode(ret, resp.Body) - this.NoError(errD) - this.Equal(ret, this.testData.GetBlocks.Output) -} -*/ - -// ********************************************* Utilities ********************************************* - -func (this *WebApiSuite) get(endpoint string) *http.Response { - resp, errG := http.Get(this.sUrl + endpoint) - this.NoError(errG) - this.Equal(200, resp.StatusCode) - return resp -} - -func (this *WebApiSuite) postJson(endpoint string, v interface{}) *http.Response { - bts, errE := this.codec.EncodeBytes(v) - this.NoError(errE) - resp, errP := http.Post(this.sUrl+endpoint, "application/json", bytes.NewBuffer(bts)) - if resp.StatusCode != 200 { - bts, _ := ioutil.ReadAll(resp.Body) - fmt.Println("ERROR: " + string(bts)) - } - this.NoError(errP) - this.Equal(200, resp.StatusCode) - return resp -} - -// ********************************************* Entrypoint ********************************************* - -func TestWebApiSuite(t *testing.T) { - suite.Run(t, &WebApiSuite{}) -} -- GitLab