arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Update Til with small fixes [...]

Update Til with small fixes:
- L2Tx TxID & Type correctness done after Idxs setted
- Added PoolL2Tx signature for Exit type

Common:
- Add common.TxID Marshalers test
arnaucube root@arnaucube.com
Wed, 21 Oct 2020 17:02:20 +0200
commit

34de6412cf2c655445f4138f7a6aab864926e402

parent

006bbf33216a454dc0c6e9b99057e0fc5f78b811

3 files changed, 35 insertions(+), 8 deletions(-)

jump to
M common/tx_test.go → common/tx_test.go

@@ -25,3 +25,21 @@ assert.NoError(t, err)

assert.NoError(t, scan.Scan(fromDB)) assert.Equal(t, value, scan) } + +func TestTxIDMarshalers(t *testing.T) { + h := []byte("0x00000000000001e240004700") + var txid TxID + err := txid.UnmarshalText(h) + assert.Nil(t, err) + assert.Equal(t, h, []byte(txid.String())) + + h2, err := txid.MarshalText() + assert.Nil(t, err) + assert.Equal(t, h, h2) + + var txid2 TxID + err = txid2.UnmarshalText(h2) + assert.Nil(t, err) + assert.Equal(t, h2, []byte(txid2.String())) + assert.Equal(t, h, h2) +}
M test/til/txs.go → test/til/txs.go

@@ -198,11 +198,6 @@ Amount: big.NewInt(int64(inst.amount)),

Fee: common.FeeSelector(inst.fee), Type: common.TxTypeTransfer, } - nTx, err := common.NewPoolL2Tx(tx.PoolL2Tx()) - if err != nil { - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) - } - tx = nTx.L2Tx() tx.BatchNum = common.BatchNum(tc.currBatchNum) // when converted to PoolL2Tx BatchNum parameter is lost testTx := L2Tx{ lineNum: inst.lineNum,

@@ -371,6 +366,9 @@ testTx.L2Tx.FromIdx = tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID].Idx

if testTx.L2Tx.Type == common.TxTypeTransfer { testTx.L2Tx.ToIdx = tc.Users[testTx.toIdxName].Accounts[testTx.tokenID].Idx } + // in case Type==Exit, ToIdx=1, already set at the + // GenerateBlocks main switch inside TxTypeExit case + nTx, err := common.NewL2Tx(&testTx.L2Tx) if err != nil { return fmt.Errorf("Line %d: %s", testTx.lineNum, err.Error())

@@ -466,7 +464,7 @@ toSign, err := tx.HashToSign()

if err != nil { return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) } - sig := tc.Users[inst.to].BJJ.SignPoseidon(toSign) + sig := tc.Users[inst.from].BJJ.SignPoseidon(toSign) tx.Signature = sig.Compress() txs = append(txs, tx)

@@ -480,6 +478,18 @@ Amount: big.NewInt(int64(inst.amount)),

Nonce: tc.Users[inst.from].Accounts[inst.tokenID].Nonce, Type: common.TxTypeExit, } + nTx, err := common.NewPoolL2Tx(&tx) + if err != nil { + return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + } + tx = *nTx + // perform signature and set it to tx.Signature + toSign, err := tx.HashToSign() + if err != nil { + return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + } + sig := tc.Users[inst.from].BJJ.SignPoseidon(toSign) + tx.Signature = sig.Compress() txs = append(txs, tx) default: return nil, fmt.Errorf("Line %d: instruction type unrecognized: %s", inst.lineNum, inst.typ)
M test/til/txs_test.go → test/til/txs_test.go

@@ -148,8 +148,7 @@ assert.Equal(t, batchNum, tx.BatchNum)

assert.Equal(t, nonce, tx.Nonce) } -//nolint the test is broken, and this is done on purpose to avoid execution -func testGeneratePoolL2Txs(t *testing.T) { +func TestGeneratePoolL2Txs(t *testing.T) { set := ` Type: Blockchain RegisterToken(1)