mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-06 19:06:42 +01:00
Add TxID calculation & New{Layer}Tx Type
Add TxID calculation & New{Layer}Tx Type
New{Layer}Tx methods that compute the `TxID` & `TxType` values from the
transaction values:
- NewL1Tx
- NewL2Tx
- NewPoolL2Tx
Add TxID Scanner & Valuer for database/sql
HistoryDB & L2DB & API packages tests will need to be addapted to the
TestTransaction generation once is done.
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/mitchellh/copystructure"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const apiPort = ":4010"
|
||||
@@ -165,7 +166,7 @@ func TestMain(m *testing.M) {
|
||||
// Gen L1Txs and add them to DB
|
||||
const totalL1Txs = 40
|
||||
const userL1Txs = 4
|
||||
usrL1Txs, othrL1Txs := test.GenL1Txs(0, totalL1Txs, userL1Txs, &usrAddr, accs, tokens, blocks, batches)
|
||||
usrL1Txs, othrL1Txs := test.GenL1Txs(256, totalL1Txs, userL1Txs, &usrAddr, accs, tokens, blocks, batches)
|
||||
var l1Txs []common.L1Tx
|
||||
l1Txs = append(l1Txs, usrL1Txs...)
|
||||
l1Txs = append(l1Txs, othrL1Txs...)
|
||||
@@ -176,7 +177,7 @@ func TestMain(m *testing.M) {
|
||||
// Gen L2Txs and add them to DB
|
||||
const totalL2Txs = 20
|
||||
const userL2Txs = 4
|
||||
usrL2Txs, othrL2Txs := test.GenL2Txs(totalL1Txs, totalL2Txs, userL2Txs, &usrAddr, accs, tokens, blocks, batches)
|
||||
usrL2Txs, othrL2Txs := test.GenL2Txs(256+totalL1Txs, totalL2Txs, userL2Txs, &usrAddr, accs, tokens, blocks, batches)
|
||||
var l2Txs []common.L2Tx
|
||||
l2Txs = append(l2Txs, usrL2Txs...)
|
||||
l2Txs = append(l2Txs, othrL2Txs...)
|
||||
@@ -369,7 +370,7 @@ func TestGetHistoryTxs(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
idxTxs := historyTxAPIs{}
|
||||
for i := 0; i < len(tc.allTxs); i++ {
|
||||
if tc.allTxs[i].FromIdx == idx {
|
||||
if tc.allTxs[i].FromIdx[6:] == idx[6:] {
|
||||
idxTxs = append(idxTxs, tc.allTxs[i])
|
||||
}
|
||||
}
|
||||
@@ -479,7 +480,7 @@ func TestGetHistoryTxs(t *testing.T) {
|
||||
}
|
||||
|
||||
func assertHistoryTxAPIs(t *testing.T, expected, actual historyTxAPIs) {
|
||||
assert.Equal(t, len(expected), len(actual))
|
||||
require.Equal(t, len(expected), len(actual))
|
||||
for i := 0; i < len(actual); i++ { //nolint len(actual) won't change within the loop
|
||||
assert.Equal(t, expected[i].Timestamp.Unix(), actual[i].Timestamp.Unix())
|
||||
expected[i].Timestamp = actual[i].Timestamp
|
||||
|
||||
@@ -55,7 +55,7 @@ type l2Info struct {
|
||||
|
||||
type historyTxAPI struct {
|
||||
IsL1 string `json:"L1orL2"`
|
||||
TxID common.TxID `json:"id"`
|
||||
TxID string `json:"id"`
|
||||
Type common.TxType `json:"type"`
|
||||
Position int `json:"position"`
|
||||
FromIdx string `json:"fromAccountIndex"`
|
||||
@@ -73,7 +73,7 @@ func historyTxsToAPI(dbTxs []*historydb.HistoryTx) []historyTxAPI {
|
||||
apiTxs := []historyTxAPI{}
|
||||
for i := 0; i < len(dbTxs); i++ {
|
||||
apiTx := historyTxAPI{
|
||||
TxID: dbTxs[i].TxID,
|
||||
TxID: dbTxs[i].TxID.String(),
|
||||
Type: dbTxs[i].Type,
|
||||
Position: dbTxs[i].Position,
|
||||
FromIdx: idxToHez(dbTxs[i].FromIdx, dbTxs[i].TokenSymbol),
|
||||
|
||||
@@ -1421,7 +1421,7 @@ components:
|
||||
TransactionId:
|
||||
type: string
|
||||
description: Identifier for transactions. Used for any kind of transaction (both L1 and L2). More info on how the identifiers are built [here](https://idocs.hermez.io/#/spec/architecture/db/README?id=txid)
|
||||
example: "0x0040e2010000000000470000"
|
||||
example: "0x00000000000001e240004700"
|
||||
EthereumAddress:
|
||||
type: string
|
||||
description: "Address of an Etherum account."
|
||||
|
||||
Reference in New Issue
Block a user