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

View File

@@ -10,6 +10,19 @@ import (
"github.com/stretchr/testify/assert"
)
func TestNewPoolL2Tx(t *testing.T) {
poolL2Tx := &PoolL2Tx{
FromIdx: 87654,
ToIdx: 300,
Amount: big.NewInt(4),
TokenID: 5,
Nonce: 144,
}
poolL2Tx, err := NewPoolL2Tx(poolL2Tx)
assert.Nil(t, err)
assert.Equal(t, "0x020000000156660000000090", poolL2Tx.TxID.String())
}
func TestTxCompressedData(t *testing.T) {
var sk babyjub.PrivateKey
_, err := hex.Decode(sk[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))