Browse Source

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
feature/sql-semaphore1
arnaucube 4 years ago
parent
commit
34de6412cf
3 changed files with 35 additions and 8 deletions
  1. +18
    -0
      common/tx_test.go
  2. +16
    -6
      test/til/txs.go
  3. +1
    -2
      test/til/txs_test.go

+ 18
- 0
common/tx_test.go

@ -25,3 +25,21 @@ func TestTxIDScannerValue(t *testing.T) {
assert.NoError(t, scan.Scan(fromDB)) assert.NoError(t, scan.Scan(fromDB))
assert.Equal(t, value, scan) 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)
}

+ 16
- 6
test/til/txs.go

@ -198,11 +198,6 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
Fee: common.FeeSelector(inst.fee), Fee: common.FeeSelector(inst.fee),
Type: common.TxTypeTransfer, 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 tx.BatchNum = common.BatchNum(tc.currBatchNum) // when converted to PoolL2Tx BatchNum parameter is lost
testTx := L2Tx{ testTx := L2Tx{
lineNum: inst.lineNum, lineNum: inst.lineNum,
@ -371,6 +366,9 @@ func (tc *Context) setIdxs() error {
if testTx.L2Tx.Type == common.TxTypeTransfer { if testTx.L2Tx.Type == common.TxTypeTransfer {
testTx.L2Tx.ToIdx = tc.Users[testTx.toIdxName].Accounts[testTx.tokenID].Idx 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) nTx, err := common.NewL2Tx(&testTx.L2Tx)
if err != nil { if err != nil {
return fmt.Errorf("Line %d: %s", testTx.lineNum, err.Error()) return fmt.Errorf("Line %d: %s", testTx.lineNum, err.Error())
@ -466,7 +464,7 @@ func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) 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() tx.Signature = sig.Compress()
txs = append(txs, tx) txs = append(txs, tx)
@ -480,6 +478,18 @@ func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) {
Nonce: tc.Users[inst.from].Accounts[inst.tokenID].Nonce, Nonce: tc.Users[inst.from].Accounts[inst.tokenID].Nonce,
Type: common.TxTypeExit, 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) txs = append(txs, tx)
default: default:
return nil, fmt.Errorf("Line %d: instruction type unrecognized: %s", inst.lineNum, inst.typ) return nil, fmt.Errorf("Line %d: instruction type unrecognized: %s", inst.lineNum, inst.typ)

+ 1
- 2
test/til/txs_test.go

@ -148,8 +148,7 @@ func (tc *Context) checkL2TxParams(t *testing.T, tx common.L2Tx, typ common.TxTy
assert.Equal(t, nonce, tx.Nonce) 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 := ` set := `
Type: Blockchain Type: Blockchain
RegisterToken(1) RegisterToken(1)

Loading…
Cancel
Save