From b3a56f618a8d0984bc68793d6ae1a845c1d12237 Mon Sep 17 00:00:00 2001
From: Silas Davis <silas@erisindustries.com>
Date: Fri, 24 Feb 2017 23:45:11 +0000
Subject: [PATCH] Change BroadcastTx to use tx.Tx

---
 rpc/v0/codec.go                           |   2 +-
 rpc/v0/json_rpc_server_test.go            |  48 ++++
 rpc/v0/json_service.go                    |   2 +-
 rpc/v0/json_service_data_test.go          |   2 +-
 rpc/v0/methods.go                         |   4 +-
 rpc/v0/params.go                          |   2 +-
 rpc/v0/restServer.go                      |   2 +-
 rpc/v0/restServer_data_test.go            |   2 +-
 rpc/v0/restServer_pipe_test.go            |   2 +-
 rpc/v0/restServer_test.go                 |   2 +-
 rpc/v0/wsService.go                       |   2 +-
 test/testdata/filters/testdata_filters.g_ | 299 ----------------------
 12 files changed, 59 insertions(+), 310 deletions(-)
 create mode 100644 rpc/v0/json_rpc_server_test.go
 delete mode 100644 test/testdata/filters/testdata_filters.g_

diff --git a/rpc/v0/codec.go b/rpc/v0/codec.go
index 344c1c98..e32d6fee 100644
--- a/rpc/v0/codec.go
+++ b/rpc/v0/codec.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package rpc_v0
+package v0
 
 import (
 	"io"
diff --git a/rpc/v0/json_rpc_server_test.go b/rpc/v0/json_rpc_server_test.go
new file mode 100644
index 00000000..d123beb3
--- /dev/null
+++ b/rpc/v0/json_rpc_server_test.go
@@ -0,0 +1,48 @@
+// Copyright 2017 Monax Industries Limited
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package v0
+
+import (
+	"fmt"
+	"testing"
+
+	"github.com/eris-ltd/eris-db/account"
+	"github.com/eris-ltd/eris-db/manager/eris-mint/evm/opcodes"
+	"github.com/eris-ltd/eris-db/txs"
+	"github.com/stretchr/testify/assert"
+	"github.com/tendermint/go-wire"
+)
+
+func TestBroadcastTx(t *testing.T) {
+	testData := LoadTestData()
+	pipe := NewMockPipe(testData)
+	methods := NewErisDbMethods(NewTCodec(), pipe)
+	pubKey := account.GenPrivAccount().PubKey
+	address := []byte{1}
+	code := opcodes.Bytecode(opcodes.PUSH1, 1, opcodes.PUSH1, 1, opcodes.ADD)
+	var tx txs.Tx = txs.NewCallTxWithNonce(pubKey, address, code, 10, 2,
+		1, 0)
+	jsonBytes := wire.JSONBytesPretty(wrappedTx{tx})
+	fmt.Println(string(jsonBytes))
+	request := NewRPCRequest("TestBroadcastTx", "BroacastTx", jsonBytes)
+	_, _, err := methods.BroadcastTx(request, "TestBroadcastTx")
+	assert.NoError(t, err)
+}
+
+// Allows us to get the type byte included but then omit the outer struct and
+// embedded field
+type wrappedTx struct {
+	txs.Tx `json:"unwrap"`
+}
diff --git a/rpc/v0/json_service.go b/rpc/v0/json_service.go
index 77bc4ffa..05dfb177 100644
--- a/rpc/v0/json_service.go
+++ b/rpc/v0/json_service.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package rpc_v0
+package v0
 
 import (
 	"encoding/json"
diff --git a/rpc/v0/json_service_data_test.go b/rpc/v0/json_service_data_test.go
index 96be0413..f618b263 100644
--- a/rpc/v0/json_service_data_test.go
+++ b/rpc/v0/json_service_data_test.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package rpc_v0
+package v0
 
 import (
 	"encoding/json"
diff --git a/rpc/v0/methods.go b/rpc/v0/methods.go
index 6a26848c..bc661dd3 100644
--- a/rpc/v0/methods.go
+++ b/rpc/v0/methods.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package rpc_v0
+package v0
 
 import (
 	"github.com/eris-ltd/eris-db/blockchain"
@@ -361,7 +361,7 @@ func (erisDbMethods *ErisDbMethods) CallCode(request *rpc.RPCRequest, requester
 func (erisDbMethods *ErisDbMethods) BroadcastTx(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) {
 	// Accept all transaction types as parameter for broadcast.
 	param := new(txs.Tx)
-	err := erisDbMethods.codec.DecodeBytesPtr(param, request.Params)
+	err := erisDbMethods.codec.DecodeBytes(param, request.Params)
 	if err != nil {
 		return nil, rpc.INVALID_PARAMS, err
 	}
diff --git a/rpc/v0/params.go b/rpc/v0/params.go
index e6f56555..a33665c4 100644
--- a/rpc/v0/params.go
+++ b/rpc/v0/params.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package rpc_v0
+package v0
 
 import (
 	"github.com/eris-ltd/eris-db/account"
diff --git a/rpc/v0/restServer.go b/rpc/v0/restServer.go
index 18fb507e..bc89b422 100644
--- a/rpc/v0/restServer.go
+++ b/rpc/v0/restServer.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package rpc_v0
+package v0
 
 import (
 	"encoding/hex"
diff --git a/rpc/v0/restServer_data_test.go b/rpc/v0/restServer_data_test.go
index 31fbaeb3..c62c6f62 100644
--- a/rpc/v0/restServer_data_test.go
+++ b/rpc/v0/restServer_data_test.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package rpc_v0
+package v0
 
 import (
 	account "github.com/eris-ltd/eris-db/account"
diff --git a/rpc/v0/restServer_pipe_test.go b/rpc/v0/restServer_pipe_test.go
index 6b084b9e..a45e88ec 100644
--- a/rpc/v0/restServer_pipe_test.go
+++ b/rpc/v0/restServer_pipe_test.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package rpc_v0
+package v0
 
 import (
 	"fmt"
diff --git a/rpc/v0/restServer_test.go b/rpc/v0/restServer_test.go
index 7cdf2803..77400a46 100644
--- a/rpc/v0/restServer_test.go
+++ b/rpc/v0/restServer_test.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package rpc_v0
+package v0
 
 // Basic imports
 import (
diff --git a/rpc/v0/wsService.go b/rpc/v0/wsService.go
index daea0d01..6e1eb984 100644
--- a/rpc/v0/wsService.go
+++ b/rpc/v0/wsService.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package rpc_v0
+package v0
 
 import (
 	"encoding/json"
diff --git a/test/testdata/filters/testdata_filters.g_ b/test/testdata/filters/testdata_filters.g_
deleted file mode 100644
index fefc112e..00000000
--- a/test/testdata/filters/testdata_filters.g_
+++ /dev/null
@@ -1,299 +0,0 @@
-package filters
-
-import (
-	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"
-)
-
-var testDataJson = `{
-  "chain_data": {
-    "priv_validator": {
-      "address": "37236DF251AB70022B1DA351F08A20FB52443E37",
-      "pub_key": [1, "CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"],
-      "priv_key": [1, "6B72D45EB65F619F11CE580C8CAED9E0BADC774E9C9C334687A65DCBAD2C4151CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"],
-      "last_height": 0,
-      "last_round": 0,
-      "last_step": 0
-    },
-    "genesis": {
-      "chain_id": "my_tests",
-      "accounts": [
-        {
-          "address": "1000000000000000000000000000000000000000",
-          "amount": 0
-        },
-        {
-          "address": "0000000000000000000000000000000000000001",
-          "amount": 1
-        },
-        {
-          "address": "0000000000000000000000000000000000000002",
-          "amount": 2
-        },
-        {
-          "address": "0000000000000000000000000000000000000003",
-          "amount": 3
-        },
-        {
-          "address": "0000000000000000000000000000000000000004",
-          "amount": 4
-        },
-        {
-          "address": "0000000000000000000000000000000000000005",
-          "amount": 5
-        },
-        {
-          "address": "0000000000000000000000000000000000000006",
-          "amount": 6
-        },
-        {
-          "address": "0000000000000000000000000000000000000007",
-          "amount": 7
-        },
-        {
-          "address": "0000000000000000000000000000000000000008",
-          "amount": 8
-        },
-        {
-          "address": "0000000000000000000000000000000000000009",
-          "amount": 9
-        },
-        {
-          "address": "000000000000000000000000000000000000000A",
-          "amount": 10
-        },
-        {
-          "address": "000000000000000000000000000000000000000B",
-          "amount": 11
-        },
-        {
-          "address": "000000000000000000000000000000000000000C",
-          "amount": 12
-        },
-        {
-          "address": "000000000000000000000000000000000000000D",
-          "amount": 13
-        },
-        {
-          "address": "000000000000000000000000000000000000000E",
-          "amount": 14
-        },
-        {
-          "address": "000000000000000000000000000000000000000F",
-          "amount": 15
-        }
-      ],
-      "validators": [
-        {
-          "pub_key": "CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906",
-          "amount": 5000000000,
-          "unbond_to": [
-            {
-              "address": "93E243AC8A01F723DE353A4FA1ED911529CCB6E5",
-              "amount": 5000000000
-            }
-          ]
-        }
-      ]
-    }
-  },
-  "GetAccounts0": {
-    "input": [
-      {
-        "field": "balance",
-        "op": "==",
-        "value": "0"
-      }
-    ],
-    "output": {
-      "accounts": [
-        {
-          "address": "1000000000000000000000000000000000000000",
-          "pub_key": null,
-          "sequence": 0,
-          "balance": 0,
-          "code": "",
-          "storage_root": "",
-          "permissions": {
-            "base": {
-              "perms": 0,
-              "set": 0
-            },
-            "roles": []
-          }
-        }
-      ]
-    }
-  },
-  "GetAccounts1": {
-    "input": [
-      {
-        "field": "balance",
-        "op": ">",
-        "value": "12"
-      }
-    ],
-    "output": {
-      "accounts": [
-        {
-	      "address": "0000000000000000000000000000000000000000",
-	      "pub_key": null,
-	      "sequence": 0,
-	      "balance": 1337,
-	      "code": "",
-	      "storage_root": "",
-	      "permissions": {
-	        "base": {
-	          "perms": 2302,
-	          "set": 16383
-	        },
-	        "roles": [
-
-	        ]
-	      }
-	    },
-        {
-          "address": "000000000000000000000000000000000000000D",
-          "pub_key": null,
-          "sequence": 0,
-          "balance": 13,
-          "code": "",
-          "storage_root": "",
-          "permissions": {
-            "base": {
-              "perms": 0,
-              "set": 0
-            },
-            "roles": []
-          }
-        },
-        {
-          "address": "000000000000000000000000000000000000000E",
-          "pub_key": null,
-          "sequence": 0,
-          "balance": 14,
-          "code": "",
-          "storage_root": "",
-          "permissions": {
-            "base": {
-              "perms": 0,
-              "set": 0
-            },
-            "roles": []
-          }
-        },
-        {
-          "address": "000000000000000000000000000000000000000F",
-          "pub_key": null,
-          "sequence": 0,
-          "balance": 15,
-          "code": "",
-          "storage_root": "",
-          "permissions": {
-            "base": {
-              "perms": 0,
-              "set": 0
-            },
-            "roles": []
-          }
-        }
-      ]
-    }
-  },
-  "GetAccounts2": {
-    "input": [
-      {
-        "field": "balance",
-        "op": ">=",
-        "value": "5"
-      },
-      {
-        "field": "balance",
-        "op": "<",
-        "value": "8"
-      }
-    ],
-    "output": {
-      "accounts": [
-        {
-          "address": "0000000000000000000000000000000000000005",
-          "pub_key": null,
-          "sequence": 0,
-          "balance": 5,
-          "code": "",
-          "storage_root": "",
-          "permissions": {
-            "base": {
-              "perms": 0,
-              "set": 0
-            },
-            "roles": []
-          }
-        },
-        {
-          "address": "0000000000000000000000000000000000000006",
-          "pub_key": null,
-          "sequence": 0,
-          "balance": 6,
-          "code": "",
-          "storage_root": "",
-          "permissions": {
-            "base": {
-              "perms": 0,
-              "set": 0
-            },
-            "roles": []
-          }
-        },
-        {
-          "address": "0000000000000000000000000000000000000007",
-          "pub_key": null,
-          "sequence": 0,
-          "balance": 7,
-          "code": "",
-          "storage_root": "",
-          "permissions": {
-            "base": {
-              "perms": 0,
-              "set": 0
-            },
-            "roles": []
-          }
-        }
-      ]
-    }
-  }
-}`
-
-var serverDuration uint = 100
-
-type (
-	ChainData struct {
-		PrivValidator *types.PrivValidator `json:"priv_validator"`
-		Genesis       *stypes.GenesisDoc   `json:"genesis"`
-	}
-
-	GetAccountData struct {
-		Input  []*event.FilterData `json:"input"`
-		Output *core_types.AccountList  `json:"output"`
-	}
-
-	TestData struct {
-		ChainData    *ChainData `json:"chain_data"`
-		GetAccounts0 *GetAccountData
-		GetAccounts1 *GetAccountData
-		GetAccounts2 *GetAccountData
-	}
-)
-
-func LoadTestData() *TestData {
-	codec := core_types.NewTCodec()
-	testData := &TestData{}
-	err := codec.DecodeBytes(testData, []byte(testDataJson))
-	if err != nil {
-		panic(err)
-	}
-	return testData
-}
-- 
GitLab