Rename load amount to deposit amount

This commit is contained in:
Arnau B
2020-12-04 13:20:18 +01:00
parent 2dd6d82dbe
commit 445f26ec9f
26 changed files with 519 additions and 519 deletions

View File

@@ -63,15 +63,15 @@ const (
// Instruction is the data structure that represents one line of code
type Instruction struct {
LineNum int
Literal string
From string
To string
Amount *big.Int
LoadAmount *big.Int
Fee uint8
TokenID common.TokenID
Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
LineNum int
Literal string
From string
To string
Amount *big.Int
DepositAmount *big.Int
Fee uint8
TokenID common.TokenID
Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
}
// parsedSet contains the full Set of Instructions representing a full code
@@ -94,7 +94,7 @@ func (i Instruction) String() string {
if i.Typ == common.TxTypeDeposit ||
i.Typ == common.TxTypeDepositTransfer ||
i.Typ == common.TxTypeCreateAccountDepositTransfer {
fmt.Fprintf(buf, "LoadAmount: %d, ", i.LoadAmount)
fmt.Fprintf(buf, "DepositAmount: %d, ", i.DepositAmount)
}
if i.Typ != common.TxTypeDeposit {
fmt.Fprintf(buf, "Amount: %d, ", i.Amount)
@@ -123,7 +123,7 @@ func (i Instruction) raw() string {
if i.Typ == common.TxTypeDeposit ||
i.Typ == common.TxTypeDepositTransfer ||
i.Typ == common.TxTypeCreateAccountDepositTransfer {
fmt.Fprintf(buf, "%d", i.LoadAmount)
fmt.Fprintf(buf, "%d", i.DepositAmount)
}
if i.Typ != common.TxTypeDeposit {
fmt.Fprintf(buf, "%d", i.Amount)
@@ -439,13 +439,13 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
// deposit case
_, lit = p.scanIgnoreWhitespace()
c.Literal += lit
loadAmount, ok := new(big.Int).SetString(lit, 10)
depositAmount, ok := new(big.Int).SetString(lit, 10)
if !ok {
line, _ := p.s.r.ReadString('\n')
c.Literal += line
return c, tracerr.Wrap(fmt.Errorf("Can not parse number for LoadAmount"))
return c, tracerr.Wrap(fmt.Errorf("Can not parse number for DepositAmount"))
}
c.LoadAmount = loadAmount
c.DepositAmount = depositAmount
if err := p.expectChar(c, ","); err != nil {
return c, tracerr.Wrap(err)
}
@@ -460,7 +460,7 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
}
if c.Typ == common.TxTypeDeposit ||
c.Typ == common.TxTypeCreateAccountDeposit {
c.LoadAmount = amount
c.DepositAmount = amount
} else {
c.Amount = amount
}

View File

@@ -72,7 +72,7 @@ func TestParseBlockchainTxs(t *testing.T) {
assert.Equal(t, TxTypeCreateAccountDepositCoordinator, instructions.instructions[7].Typ)
assert.Equal(t, TypeNewBatch, instructions.instructions[11].Typ)
assert.Equal(t, "Deposit(1)User0:20", instructions.instructions[16].raw())
assert.Equal(t, "Type: DepositTransfer, From: A, To: B, LoadAmount: 15, Amount: 10, Fee: 0, TokenID: 1\n", instructions.instructions[13].String())
assert.Equal(t, "Type: DepositTransfer, From: A, To: B, DepositAmount: 15, Amount: 10, Fee: 0, TokenID: 1\n", instructions.instructions[13].String())
assert.Equal(t, "Type: Transfer, From: User1, To: User0, Amount: 15, Fee: 1, TokenID: 3\n", instructions.instructions[19].String())
assert.Equal(t, "Transfer(2)A-B:15(1)", instructions.instructions[15].raw())
assert.Equal(t, "Type: Transfer, From: A, To: B, Amount: 15, Fee: 1, TokenID: 2\n", instructions.instructions[15].String())

View File

@@ -199,12 +199,12 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
}
tx := common.L1Tx{
FromEthAddr: tc.Users[inst.From].Addr,
FromBJJ: tc.Users[inst.From].BJJ.Public(),
TokenID: inst.TokenID,
Amount: big.NewInt(0),
LoadAmount: big.NewInt(0),
Type: common.TxTypeCreateAccountDeposit, // as TxTypeCreateAccountDepositCoordinator is not valid oustide Til package
FromEthAddr: tc.Users[inst.From].Addr,
FromBJJ: tc.Users[inst.From].BJJ.Public(),
TokenID: inst.TokenID,
Amount: big.NewInt(0),
DepositAmount: big.NewInt(0),
Type: common.TxTypeCreateAccountDeposit, // as TxTypeCreateAccountDepositCoordinator is not valid oustide Til package
}
testTx := L1Tx{
lineNum: inst.LineNum,
@@ -219,12 +219,12 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
}
tx := common.L1Tx{
FromEthAddr: tc.Users[inst.From].Addr,
FromBJJ: tc.Users[inst.From].BJJ.Public(),
TokenID: inst.TokenID,
Amount: big.NewInt(0),
LoadAmount: inst.LoadAmount,
Type: inst.Typ,
FromEthAddr: tc.Users[inst.From].Addr,
FromBJJ: tc.Users[inst.From].BJJ.Public(),
TokenID: inst.TokenID,
Amount: big.NewInt(0),
DepositAmount: inst.DepositAmount,
Type: inst.Typ,
}
if inst.Typ == common.TxTypeCreateAccountDepositTransfer {
tx.Amount = inst.Amount
@@ -248,10 +248,10 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
}
tx := common.L1Tx{
TokenID: inst.TokenID,
Amount: big.NewInt(0),
LoadAmount: inst.LoadAmount,
Type: inst.Typ,
TokenID: inst.TokenID,
Amount: big.NewInt(0),
DepositAmount: inst.DepositAmount,
Type: inst.Typ,
}
if inst.Typ == common.TxTypeDepositTransfer {
tx.Amount = inst.Amount
@@ -291,10 +291,10 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
}
tx := common.L1Tx{
TokenID: inst.TokenID,
Amount: inst.Amount,
LoadAmount: big.NewInt(0),
Type: common.TxTypeForceTransfer,
TokenID: inst.TokenID,
Amount: inst.Amount,
DepositAmount: big.NewInt(0),
Type: common.TxTypeForceTransfer,
}
testTx := L1Tx{
lineNum: inst.LineNum,
@@ -332,11 +332,11 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
}
tx := common.L1Tx{
ToIdx: common.Idx(1), // as is an Exit
TokenID: inst.TokenID,
Amount: inst.Amount,
LoadAmount: big.NewInt(0),
Type: common.TxTypeForceExit,
ToIdx: common.Idx(1), // as is an Exit
TokenID: inst.TokenID,
Amount: inst.Amount,
DepositAmount: big.NewInt(0),
Type: common.TxTypeForceExit,
}
testTx := L1Tx{
lineNum: inst.LineNum,
@@ -747,7 +747,7 @@ func (tc *Context) FillBlocksL1UserTxsBatchNum(blocks []common.BlockData) {
// FillBlocksForgedL1UserTxs fills the L1UserTxs of a batch with the L1UserTxs
// that are forged in that batch. It always sets `EffectiveAmount` = `Amount`
// and `EffectiveLoadAmount` = `LoadAmount`.
// and `EffectiveDepositAmount` = `DepositAmount`.
func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
for i := range blocks {
block := &blocks[i]
@@ -761,7 +761,7 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
tx := &batch.L1UserTxs[k]
*tx = queue[k].L1Tx
tx.EffectiveAmount = tx.Amount
tx.EffectiveLoadAmount = tx.LoadAmount
tx.EffectiveDepositAmount = tx.DepositAmount
tx.BatchNum = &batchNum
_tx, err := common.NewL1Tx(tx)
if err != nil {
@@ -786,7 +786,7 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EthBlockNum
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].Position
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveAmount
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveLoadAmount
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveDepositAmount
// - blocks[].Rollup.Batch.L2Txs[].TxID
// - blocks[].Rollup.Batch.L2Txs[].Position
// - blocks[].Rollup.Batch.L2Txs[].Nonce
@@ -869,7 +869,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra)
tx.Position = position
position++
tx.EffectiveAmount = big.NewInt(0)
tx.EffectiveLoadAmount = big.NewInt(0)
tx.EffectiveDepositAmount = big.NewInt(0)
nTx, err := common.NewL1Tx(tx)
if err != nil {
return tracerr.Wrap(err)

View File

@@ -141,7 +141,7 @@ func TestGenerateBlocks(t *testing.T) {
tc.checkL2TxParams(t, blocks[1].Rollup.Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6))
}
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, loadAmount, amount *big.Int) {
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, depositAmount, amount *big.Int) {
assert.Equal(t, typ, tx.Type)
if tx.FromIdx != common.Idx(0) {
assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
@@ -151,8 +151,8 @@ func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxTy
if tx.ToIdx != common.Idx(0) {
assert.Equal(t, tc.Users[to].Accounts[tokenID].Idx, tx.ToIdx)
}
if loadAmount != nil {
assert.Equal(t, loadAmount, tx.LoadAmount)
if depositAmount != nil {
assert.Equal(t, depositAmount, tx.DepositAmount)
}
if amount != nil {
assert.Equal(t, amount, tx.Amount)
@@ -432,14 +432,14 @@ func TestGenerateFromInstructions(t *testing.T) {
TokenID: 1,
})
i++
la := big.NewInt(10)
da := big.NewInt(10)
setInst = append(setInst, Instruction{
LineNum: i,
// Literal: "CreateAccountDeposit(1) A: 10",
Typ: common.TxTypeCreateAccountDeposit,
From: "A",
TokenID: 1,
LoadAmount: la,
Typ: common.TxTypeCreateAccountDeposit,
From: "A",
TokenID: 1,
DepositAmount: da,
})
i++
setInst = append(setInst, Instruction{