Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rfct/til #42

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 3 additions & 65 deletions sequencer/test/til/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"math/big"
"sort"
"strconv"
"tokamak-sybil-resistance/common"
"tokamak-sybil-resistance/log"
)
Expand All @@ -24,13 +23,6 @@ type setType string
// SetTypeBlockchain defines the type 'Blockchain' of the set
var SetTypeBlockchain = setType("Blockchain")

// SetTypePoolL2 defines the type 'PoolL2' of the set
var SetTypePoolL2 = setType("PoolL2")

// TypeNewBatch is used for testing purposes only, and represents the
// common.TxType of a new batch
var TypeNewBatch common.TxType = "InstrTypeNewBatch"

// TypeNewBatchL1 is used for testing purposes only, and represents the
// common.TxType of a new batch
var TypeNewBatchL1 common.TxType = "InstrTypeNewBatchL1"
Expand All @@ -56,9 +48,7 @@ type Instruction struct {
To string
Amount *big.Int
DepositAmount *big.Int
Fee uint8
// TokenID common.TokenID
Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
}

// parsedSet contains the full Set of Instructions representing a full code
Expand All @@ -84,20 +74,13 @@ func (i Instruction) String() string {
if i.Typ != common.TxTypeDeposit {
fmt.Fprintf(buf, "Amount: %d\n", i.Amount)
}
// if i.Typ == common.TxTypeTransfer ||
// i.Typ == common.TxTypeDepositTransfer ||
// i.Typ == common.TxTypeCreateAccountDepositTransfer {
// fmt.Fprintf(buf, "Fee: %d, ", i.Fee)
// }
// fmt.Fprintf(buf, "TokenID: %d\n", i.TokenID)
return buf.String()
}

// Raw returns a string with the raw representation of the Instruction
func (i Instruction) raw() string {
buf := bytes.NewBufferString("")
fmt.Fprintf(buf, "%s", i.Typ)
// fmt.Fprintf(buf, "(%d)", i.TokenID)
fmt.Fprintf(buf, "%s", i.From)
if i.Typ == common.TxTypeCreateVouch ||
i.Typ == common.TxTypeDeleteVouch {
Expand Down Expand Up @@ -264,14 +247,8 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
_, _ = p.s.r.ReadString('\n')
return nil, errCommentLine
} else if lit == ">" {
if setType == SetTypePoolL2 {
return c, common.Wrap(fmt.Errorf("unexpected '>' at PoolL2Txs set"))
}
_, lit = p.scanIgnoreWhitespace()
if lit == "batch" {
_, _ = p.s.r.ReadString('\n')
return &Instruction{Typ: TypeNewBatch}, errNewEventLine
} else if lit == "batchL1" {
if lit == "batchL1" {
_, _ = p.s.r.ReadString('\n')
return &Instruction{Typ: TypeNewBatchL1}, errNewEventLine
} else if lit == "block" {
Expand All @@ -287,8 +264,6 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
_, lit = p.scanIgnoreWhitespace()
if lit == "Blockchain" {
return &Instruction{Typ: "Blockchain"}, errSetTypeLine
} else if lit == "PoolL2" {
return &Instruction{Typ: "PoolL2"}, errSetTypeLine
} else {
return c,
common.Wrap(fmt.Errorf("invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", lit))
Expand All @@ -299,7 +274,6 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
return c, common.Wrap(fmt.Errorf("set type not defined"))
}
vouch := false
fee := false

if setType == SetTypeBlockchain {
switch lit {
Expand All @@ -318,17 +292,6 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
default:
return c, common.Wrap(fmt.Errorf("unexpected Blockchain tx type: %s", lit))
}
} else if setType == SetTypePoolL2 {
switch lit {
case "PoolCreateVouch":
c.Typ = common.TxTypeCreateVouch
vouch = true
case "PoolDeleteVouch":
c.Typ = common.TxTypeDeleteVouch
vouch = true
default:
return c, common.Wrap(fmt.Errorf("unexpected PoolL2 tx type: %s", lit))
}
} else {
return c,
common.Wrap(fmt.Errorf("invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'",
Expand Down Expand Up @@ -376,29 +339,6 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
} else {
c.Amount = amount
}
if fee {
if err := p.expectChar(c, "("); err != nil {
return c, common.Wrap(err)
}
_, lit = p.scanIgnoreWhitespace()
c.Literal += lit
fee, err := strconv.Atoi(lit)
if err != nil {
line, _ := p.s.r.ReadString('\n')
c.Literal += line
return c, common.Wrap(err)
}
if fee > common.MaxFeePlan-1 {
line, _ := p.s.r.ReadString('\n')
c.Literal += line
return c, common.Wrap(fmt.Errorf("fee %d can not be bigger than 255", fee))
}
c.Fee = uint8(fee)

if err := p.expectChar(c, ")"); err != nil {
return c, common.Wrap(err)
}
}

if tok == EOF {
return nil, common.Wrap(errof)
Expand Down Expand Up @@ -436,9 +376,7 @@ func (p *parser) parse() (*parsedSet, error) {
"there is already a previous instruction 'Type: %s' defined",
i, instruction.Typ, ps.typ))
}
if instruction.Typ == "PoolL2" {
ps.typ = SetTypePoolL2
} else if instruction.Typ == "Blockchain" {
if instruction.Typ == "Blockchain" {
ps.typ = SetTypeBlockchain
} else {
log.Fatalf("line %d: Invalid set type: '%s'. Valid set types: "+
Expand Down
14 changes: 3 additions & 11 deletions sequencer/test/til/lang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ func TestParseBlockchainTxs(t *testing.T) {
CreateVouch A-B

// set new batch
> batch
> batchL1

CreateAccountDeposit C: 5
CreateVouch B-C
Deposit User0: 20
Deposit User1: 20

> batch
> batchL1
> block

DeleteVouch A-B
Expand All @@ -44,7 +44,7 @@ func TestParseBlockchainTxs(t *testing.T) {
}
}

assert.Equal(t, TypeNewBatch, instructions.instructions[4].Typ)
assert.Equal(t, TypeNewBatchL1, instructions.instructions[4].Typ)
assert.Equal(t, "DepositUser0:20", instructions.instructions[7].raw())
assert.Equal(t, "CreateVouchA-B", instructions.instructions[3].raw())
assert.Equal(t, "DeleteVouchA-B", instructions.instructions[11].raw())
Expand Down Expand Up @@ -97,12 +97,4 @@ func TestParseErrors(t *testing.T) {
assert.Equal(t,
"line 1: Type:, err: invalid set type: 'PoolL1'. Valid set types: 'Blockchain', 'PoolL2'",
err.Error())

s = `Type: PoolL2
Type: Blockchain`
parser = newParser(strings.NewReader(s))
_, err = parser.parse()
assert.Equal(t,
"line 2: Instruction of 'Type: Blockchain' when there is already a previous "+
"instruction 'Type: PoolL2' defined", err.Error())
}
Loading
Loading