You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
arnaucube 265bdf23e3 Rename Transakcio to Til for a easier usage 4 years ago
..
README.md Rename Transakcio to Til for a easier usage 4 years ago
lang.go Rename Transakcio to Til for a easier usage 4 years ago
lang_test.go Rename Transakcio to Til for a easier usage 4 years ago
sets.go Rename Transakcio to Til for a easier usage 4 years ago
sets_test.go Rename Transakcio to Til for a easier usage 4 years ago
txs.go Rename Transakcio to Til for a easier usage 4 years ago
txs_test.go Rename Transakcio to Til for a easier usage 4 years ago

README.md

Til (Test instructions language)

Language to define sets of instructions to simulate Hermez transactions (L1 & L2) with real data.

Syntax

Global

  • Set type definition
    • Blockchain: generate the transactions that would come from the Hermez smart contract on the blockchain.
    Type: Blockchain
    
     - PoolL2: generate the transactions that would come from the Pool of L2Txs
    
     Type: PoolL2
    
    
    

Blockchain set of instructions

Available instructions:

Type: Blockchain

// register the TokenID:
RegisterToken(1)

// deposit of TokenID=1, on the account of tokenID=1 for the user A, of an
// amount of 50 units
CreateAccountDeposit(1) A: 50

// create the account of TokenID=1 for the user B, deposit of TokenID=1, on the
// account of tokenID=1 for the user B, of an amount of 40 units and atomically
// transfer 10 units to account of tokenID=1 for the user A, paying a fee of 2
CreateAccountDepositTransfer(1) B-A: 40, 10 (2)

// transaction generated by the Coordinator, create account for user User0 for
// the TokenID=2, with a deposit of 0
CreateAccountDepositCoordinator(2) User0


// deposit of TokenID=1, at the account A, of 6 units
Deposit(1) A: 6

// deposit of TokenID=1, on the account of tokenID=1 for the user B, of an
// amount of 6 units and atomically transfer 10 units to account of tokenID=1 for
// the user A, paying a fee of 2
DepositTransfer(1) B-A: 6, 4 (2)

// transfer of TokenID=1, from the account A to B (for that token), of 6 units,
// paying a fee of 3. Transaction will be a L2Tx
Transfer(1) A-B: 6 (3)

// exit of TokenID=1, from the account A (for that token), of 5 units.
// Transaction will be a L2Tx
Exit(1) A: 5

// force-transfer of TokenID=1, from the account A to B (for that token), of 6
// units, paying a fee of 3. Transaction will be L1UserTx of ForceTransfer type
ForceTransfer(1) A-B: 6 (3)

// force-exit of TokenID=1, from the account A (for that token), of 5 units.
// Transaction will be L1UserTx of ForceExit type
ForceExit(1) A: 5

// advance one batch, forging without L1UserTxs, only can contain L2Txs and
// L1CoordinatorTxs
> batch

// advance one batch, forging with L1UserTxs (and L2Txs and L1CoordinatorTxs)
> batchL1

// advance an ethereum block
> block

PoolL2 set of instructions

Available instructions:

Type: PoolL2

// transfer of TokenID=1, from the account A to B (for that token), of 6 units,
// paying a fee of 4
PoolTransfer(1) A-B: 6 (4)

// exit of TokenID=1, from the account A (for that token), of 3 units
PoolExit(1) A: 3

Usage

// create a new til.Context
tc := til.NewContext(eth.RollupConstMaxL1UserTx)

// generate Blockchain blocks data from the common.SetBlockcahin0 instructions set
blocks, err = tc.GenerateBlocks(common.SetBlockchain0)
assert.Nil(t, err)

// generate PoolL2 transactions data from the common.SetPool0 instructions set
poolL2Txs, err = tc.GenerateBlocks(common.SetPool0)
assert.Nil(t, err)

Where blocks will contain:

// BatchData contains the information of a Batch
type BatchData struct {
    L1CoordinatorTxs     []common.L1Tx
    L2Txs                []common.L2Tx
    CreatedAccounts []common.Account
}

// BlockData contains the information of a Block
type BlockData struct {
    L1UserTxs        []common.L1Tx
    Batches          []BatchData
    RegisteredTokens []common.Token
}