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:
arnaucube
2020-09-30 14:05:51 +02:00
parent c6f70f3177
commit 9bb4a4ec1b
21 changed files with 422 additions and 131 deletions

27
common/tx_test.go Normal file
View File

@@ -0,0 +1,27 @@
package common
import (
"database/sql"
"database/sql/driver"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTxIDScannerValue(t *testing.T) {
txid0 := &TxID{}
txid1 := &TxID{}
txid0B := [12]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
txid1B := [12]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
copy(txid0[:], txid0B[:])
copy(txid1[:], txid1B[:])
var value driver.Valuer
var scan sql.Scanner
value = txid0
scan = txid1
fromDB, err := value.Value()
assert.NoError(t, err)
assert.NoError(t, scan.Scan(fromDB))
assert.Equal(t, value, scan)
}