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.

567 lines
18 KiB

Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
  1. package til
  2. import (
  3. "math/big"
  4. "testing"
  5. "github.com/hermeznetwork/hermez-node/common"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. )
  9. func TestGenerateBlocksNoBatches(t *testing.T) {
  10. set := `
  11. Type: Blockchain
  12. AddToken(1)
  13. AddToken(2)
  14. CreateAccountDeposit(1) A: 11
  15. CreateAccountDeposit(2) B: 22
  16. > block
  17. `
  18. tc := NewContext(common.RollupConstMaxL1UserTx)
  19. blocks, err := tc.GenerateBlocks(set)
  20. require.NoError(t, err)
  21. assert.Equal(t, 1, len(blocks))
  22. assert.Equal(t, 0, len(blocks[0].Rollup.Batches))
  23. assert.Equal(t, 2, len(blocks[0].Rollup.AddedTokens))
  24. assert.Equal(t, 2, len(blocks[0].Rollup.L1UserTxs))
  25. }
  26. func TestGenerateBlocks(t *testing.T) {
  27. set := `
  28. Type: Blockchain
  29. AddToken(1)
  30. AddToken(2)
  31. AddToken(3)
  32. CreateAccountDeposit(1) A: 10
  33. CreateAccountDeposit(2) A: 20
  34. CreateAccountDeposit(1) B: 5
  35. CreateAccountDeposit(1) C: 5
  36. CreateAccountDeposit(1) D: 5
  37. > batchL1 // batchNum = 1
  38. > batchL1 // batchNum = 2
  39. CreateAccountDepositTransfer(1) F-A: 15, 10
  40. Transfer(1) A-B: 6 (1)
  41. Transfer(1) B-D: 3 (1)
  42. Transfer(1) A-D: 1 (1)
  43. // set new batch
  44. > batch // batchNum = 3
  45. CreateAccountCoordinator(1) E
  46. CreateAccountCoordinator(2) B
  47. DepositTransfer(1) A-B: 15, 10
  48. Transfer(1) C-A : 3 (1)
  49. Transfer(2) A-B: 15 (1)
  50. Transfer(1) A-E: 1 (1)
  51. CreateAccountDeposit(1) User0: 20
  52. CreateAccountDeposit(3) User1: 20
  53. CreateAccountCoordinator(1) User1
  54. CreateAccountCoordinator(3) User0
  55. > batchL1 // batchNum = 4
  56. Transfer(1) User0-User1: 15 (1)
  57. Transfer(3) User1-User0: 15 (1)
  58. Transfer(1) A-C: 1 (1)
  59. > batchL1 // batchNum = 5
  60. Transfer(1) User1-User0: 1 (1)
  61. > block
  62. // Exits
  63. Transfer(1) A-B: 1 (1)
  64. Exit(1) A: 5 (1)
  65. > batch // batchNum = 6
  66. > block
  67. // this transaction should not be generated, as it's after last
  68. // batch and last block
  69. Transfer(1) User1-User0: 1 (1)
  70. `
  71. tc := NewContext(common.RollupConstMaxL1UserTx)
  72. blocks, err := tc.GenerateBlocks(set)
  73. require.NoError(t, err)
  74. assert.Equal(t, 2, len(blocks))
  75. assert.Equal(t, 5, len(blocks[0].Rollup.Batches))
  76. assert.Equal(t, 1, len(blocks[1].Rollup.Batches))
  77. assert.Equal(t, 9, len(blocks[0].Rollup.L1UserTxs))
  78. assert.Equal(t, 4, len(blocks[0].Rollup.Batches[3].L1CoordinatorTxs))
  79. assert.Equal(t, 0, len(blocks[1].Rollup.L1UserTxs))
  80. // Check expected values generated by each line
  81. // #0: Deposit(1) A: 10
  82. tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[0], common.TxTypeCreateAccountDeposit, 1, "A", "", big.NewInt(10), nil)
  83. // #1: Deposit(2) A: 20
  84. tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[1], common.TxTypeCreateAccountDeposit, 2, "A", "", big.NewInt(20), nil)
  85. // // #2: Deposit(1) A: 20
  86. tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[2], common.TxTypeCreateAccountDeposit, 1, "B", "", big.NewInt(5), nil)
  87. // // #3: CreateAccountDeposit(1) C: 5
  88. tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[3], common.TxTypeCreateAccountDeposit, 1, "C", "", big.NewInt(5), nil)
  89. // // #4: CreateAccountDeposit(1) D: 5
  90. tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[4], common.TxTypeCreateAccountDeposit, 1, "D", "", big.NewInt(5), nil)
  91. // #5: Transfer(1) A-B: 6 (1)
  92. tc.checkL2TxParams(t, blocks[0].Rollup.Batches[2].L2Txs[0], common.TxTypeTransfer, 1, "A", "B", big.NewInt(6), common.BatchNum(3))
  93. // #6: Transfer(1) B-D: 3 (1)
  94. tc.checkL2TxParams(t, blocks[0].Rollup.Batches[2].L2Txs[1], common.TxTypeTransfer, 1, "B", "D", big.NewInt(3), common.BatchNum(3))
  95. // #7: Transfer(1) A-D: 1 (1)
  96. tc.checkL2TxParams(t, blocks[0].Rollup.Batches[2].L2Txs[2], common.TxTypeTransfer, 1, "A", "D", big.NewInt(1), common.BatchNum(3))
  97. // change of Batch
  98. // #8: CreateAccountDepositTransfer(1) F-A: 15, 10 (3)
  99. tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[5], common.TxTypeCreateAccountDepositTransfer, 1, "F", "A", big.NewInt(15), big.NewInt(10))
  100. // #9: DepositTransfer(1) A-B: 15, 10 (1)
  101. tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[6], common.TxTypeDepositTransfer, 1, "A", "B", big.NewInt(15), big.NewInt(10))
  102. // #11: Transfer(1) C-A : 3 (1)
  103. tc.checkL2TxParams(t, blocks[0].Rollup.Batches[3].L2Txs[0], common.TxTypeTransfer, 1, "C", "A", big.NewInt(3), common.BatchNum(4))
  104. // #12: Transfer(2) A-B: 15 (1)
  105. tc.checkL2TxParams(t, blocks[0].Rollup.Batches[3].L2Txs[1], common.TxTypeTransfer, 2, "A", "B", big.NewInt(15), common.BatchNum(4))
  106. // #13: Deposit(1) User0: 20
  107. tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[7], common.TxTypeCreateAccountDeposit, 1, "User0", "", big.NewInt(20), nil)
  108. // // #14: Deposit(3) User1: 20
  109. tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[8], common.TxTypeCreateAccountDeposit, 3, "User1", "", big.NewInt(20), nil)
  110. // #15: Transfer(1) User0-User1: 15 (1)
  111. tc.checkL2TxParams(t, blocks[0].Rollup.Batches[4].L2Txs[0], common.TxTypeTransfer, 1, "User0", "User1", big.NewInt(15), common.BatchNum(5))
  112. // #16: Transfer(3) User1-User0: 15 (1)
  113. tc.checkL2TxParams(t, blocks[0].Rollup.Batches[4].L2Txs[1], common.TxTypeTransfer, 3, "User1", "User0", big.NewInt(15), common.BatchNum(5))
  114. // #17: Transfer(1) A-C: 1 (1)
  115. tc.checkL2TxParams(t, blocks[0].Rollup.Batches[4].L2Txs[2], common.TxTypeTransfer, 1, "A", "C", big.NewInt(1), common.BatchNum(5))
  116. // change of Batch
  117. // #18: Transfer(1) User1-User0: 1 (1)
  118. tc.checkL2TxParams(t, blocks[1].Rollup.Batches[0].L2Txs[0], common.TxTypeTransfer, 1, "User1", "User0", big.NewInt(1), common.BatchNum(6))
  119. // change of Block (implies also a change of batch)
  120. // #19: Transfer(1) A-B: 1 (1)
  121. tc.checkL2TxParams(t, blocks[1].Rollup.Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6))
  122. }
  123. func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, depositAmount, amount *big.Int) {
  124. assert.Equal(t, typ, tx.Type)
  125. if tx.FromIdx != common.Idx(0) {
  126. assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
  127. }
  128. assert.Equal(t, tc.Users[from].Addr.Hex(), tx.FromEthAddr.Hex())
  129. assert.Equal(t, tc.Users[from].BJJ.Public().Compress(), tx.FromBJJ)
  130. if tx.ToIdx != common.Idx(0) {
  131. assert.Equal(t, tc.Users[to].Accounts[tokenID].Idx, tx.ToIdx)
  132. }
  133. if depositAmount != nil {
  134. assert.Equal(t, depositAmount, tx.DepositAmount)
  135. }
  136. if amount != nil {
  137. assert.Equal(t, amount, tx.Amount)
  138. }
  139. }
  140. func (tc *Context) checkL2TxParams(t *testing.T, tx common.L2Tx, typ common.TxType, tokenID common.TokenID, from, to string, amount *big.Int, batchNum common.BatchNum) {
  141. assert.Equal(t, typ, tx.Type)
  142. assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
  143. if tx.Type != common.TxTypeExit {
  144. assert.Equal(t, tc.Users[to].Accounts[tokenID].Idx, tx.ToIdx)
  145. }
  146. if amount != nil {
  147. assert.Equal(t, amount, tx.Amount)
  148. }
  149. assert.Equal(t, batchNum, tx.BatchNum)
  150. }
  151. func TestGeneratePoolL2Txs(t *testing.T) {
  152. set := `
  153. Type: Blockchain
  154. AddToken(1)
  155. AddToken(2)
  156. AddToken(3)
  157. CreateAccountDeposit(1) A: 10
  158. CreateAccountDeposit(2) A: 20
  159. CreateAccountDeposit(1) B: 5
  160. CreateAccountDeposit(1) C: 5
  161. CreateAccountDeposit(1) User0: 5
  162. CreateAccountDeposit(1) User1: 0
  163. CreateAccountDeposit(3) User0: 0
  164. CreateAccountDeposit(3) User1: 5
  165. CreateAccountDeposit(2) B: 5
  166. CreateAccountDeposit(2) D: 0
  167. > batchL1
  168. > batchL1
  169. `
  170. tc := NewContext(common.RollupConstMaxL1UserTx)
  171. _, err := tc.GenerateBlocks(set)
  172. require.NoError(t, err)
  173. set = `
  174. Type: PoolL2
  175. PoolTransfer(1) A-B: 6 (1)
  176. PoolTransfer(1) B-C: 3 (1)
  177. PoolTransfer(1) C-A: 3 (1)
  178. PoolTransfer(1) A-B: 1 (1)
  179. PoolTransfer(2) A-B: 15 (1)
  180. PoolTransfer(1) User0-User1: 15 (1)
  181. PoolTransfer(3) User1-User0: 15 (1)
  182. PoolTransfer(2) B-D: 3 (1)
  183. PoolExit(1) A: 3 (1)
  184. PoolTransferToEthAddr(1) A-B: 1 (1)
  185. PoolTransferToBJJ(1) A-B: 1 (1)
  186. `
  187. poolL2Txs, err := tc.GeneratePoolL2Txs(set)
  188. require.NoError(t, err)
  189. assert.Equal(t, 11, len(poolL2Txs))
  190. assert.Equal(t, common.TxTypeTransfer, poolL2Txs[0].Type)
  191. assert.Equal(t, common.TxTypeExit, poolL2Txs[8].Type)
  192. assert.Equal(t, tc.Users["B"].Addr.Hex(), poolL2Txs[0].ToEthAddr.Hex())
  193. assert.Equal(t, tc.Users["B"].BJJ.Public().String(), poolL2Txs[0].ToBJJ.String())
  194. assert.Equal(t, tc.Users["User1"].Addr.Hex(), poolL2Txs[5].ToEthAddr.Hex())
  195. assert.Equal(t, tc.Users["User1"].BJJ.Public().String(), poolL2Txs[5].ToBJJ.String())
  196. assert.Equal(t, common.Nonce(1), poolL2Txs[0].Nonce)
  197. assert.Equal(t, common.Nonce(2), poolL2Txs[3].Nonce)
  198. assert.Equal(t, common.Nonce(3), poolL2Txs[8].Nonce)
  199. assert.Equal(t, tc.Users["B"].Addr.Hex(), poolL2Txs[9].ToEthAddr.Hex())
  200. assert.Equal(t, common.EmptyBJJComp, poolL2Txs[9].ToBJJ)
  201. assert.Equal(t, common.TxTypeTransferToEthAddr, poolL2Txs[9].Type)
  202. assert.Equal(t, common.FFAddr, poolL2Txs[10].ToEthAddr)
  203. assert.Equal(t, tc.Users["B"].BJJ.Public().String(), poolL2Txs[10].ToBJJ.String())
  204. assert.Equal(t, common.TxTypeTransferToBJJ, poolL2Txs[10].Type)
  205. // load another set in the same Context
  206. set = `
  207. Type: PoolL2
  208. PoolTransfer(1) A-B: 6 (1)
  209. PoolTransfer(1) B-C: 3 (1)
  210. PoolTransfer(1) A-C: 3 (1)
  211. `
  212. poolL2Txs, err = tc.GeneratePoolL2Txs(set)
  213. require.NoError(t, err)
  214. assert.Equal(t, common.Nonce(6), poolL2Txs[0].Nonce)
  215. assert.Equal(t, common.Nonce(2), poolL2Txs[1].Nonce)
  216. assert.Equal(t, common.Nonce(7), poolL2Txs[2].Nonce)
  217. // check that a PoolL2Tx can be done to a non existing ToIdx
  218. set = `
  219. Type: Blockchain
  220. AddToken(1)
  221. CreateAccountDeposit(1) A: 10
  222. > batchL1
  223. > batchL1
  224. > block
  225. `
  226. tc = NewContext(common.RollupConstMaxL1UserTx)
  227. _, err = tc.GenerateBlocks(set)
  228. require.NoError(t, err)
  229. set = `
  230. Type: PoolL2
  231. PoolTransferToEthAddr(1) A-B: 3 (1)
  232. PoolTransferToBJJ(1) A-C: 3 (1)
  233. `
  234. _, err = tc.GeneratePoolL2Txs(set)
  235. require.NoError(t, err)
  236. // expect error, as FromIdx=B is still not created for TokenID=1
  237. set = `
  238. Type: PoolL2
  239. PoolTransferToEthAddr(1) B-A: 3 (1)
  240. PoolTransferToBJJ(1) B-A: 3 (1)
  241. `
  242. _, err = tc.GeneratePoolL2Txs(set)
  243. require.NotNil(t, err)
  244. }
  245. func TestGeneratePoolL2TxsFromInstructions(t *testing.T) {
  246. // Generate necessary L1 data
  247. set := `
  248. Type: Blockchain
  249. AddToken(1)
  250. CreateAccountCoordinator(1) A
  251. CreateAccountDeposit(1) B: 7
  252. > batchL1
  253. > batchL1
  254. `
  255. tc := NewContext(common.RollupConstMaxL1UserTx)
  256. _, err := tc.GenerateBlocks(set)
  257. require.NoError(t, err)
  258. // Generate Pool txs using instructions
  259. instructionSet := []Instruction{}
  260. i := 0
  261. a := big.NewInt(3)
  262. instructionSet = append(instructionSet, Instruction{
  263. LineNum: i,
  264. // Literal: "PoolTransferToEthAddr(1) B-A: 3 (1)",
  265. Typ: common.TxTypeTransferToEthAddr,
  266. From: "B",
  267. To: "A",
  268. TokenID: 1,
  269. Amount: a,
  270. Fee: 1,
  271. })
  272. i++
  273. instructionSet = append(instructionSet, Instruction{
  274. LineNum: i,
  275. // Literal: "PoolTransferToBJJ(1) B-A: 3 (1)",
  276. Typ: common.TxTypeTransferToBJJ,
  277. From: "B",
  278. To: "A",
  279. TokenID: 1,
  280. Amount: a,
  281. Fee: 1,
  282. })
  283. txsFromInstructions, err := tc.GeneratePoolL2TxsFromInstructions(instructionSet)
  284. require.NoError(t, err)
  285. // Generate Pool txs using string
  286. tc = NewContext(common.RollupConstMaxL1UserTx)
  287. _, err = tc.GenerateBlocks(set)
  288. require.NoError(t, err)
  289. stringSet := `
  290. Type: PoolL2
  291. PoolTransferToEthAddr(1) B-A: 3 (1)
  292. PoolTransferToBJJ(1) B-A: 3 (1)
  293. `
  294. txsFromString, err := tc.GeneratePoolL2Txs(stringSet)
  295. require.NoError(t, err)
  296. // Compare generated txs from instructions and string
  297. // timestamps will be different
  298. for i := 0; i < len(txsFromString); i++ {
  299. txsFromInstructions[i].Timestamp = txsFromString[i].Timestamp
  300. }
  301. assert.Equal(t, txsFromString, txsFromInstructions)
  302. }
  303. func TestGenerateErrors(t *testing.T) {
  304. // unregistered token
  305. set := `Type: Blockchain
  306. CreateAccountDeposit(1) A: 5
  307. > batchL1
  308. `
  309. tc := NewContext(common.RollupConstMaxL1UserTx)
  310. _, err := tc.GenerateBlocks(set)
  311. assert.Equal(t, "Line 2: Can not process CreateAccountDeposit: TokenID 1 not registered, last registered TokenID: 0", err.Error())
  312. // ensure AddToken sequentiality and not using 0
  313. set = `
  314. Type: Blockchain
  315. AddToken(0)
  316. `
  317. tc = NewContext(common.RollupConstMaxL1UserTx)
  318. _, err = tc.GenerateBlocks(set)
  319. require.Equal(t, "Line 2: AddToken can not register TokenID 0", err.Error())
  320. set = `
  321. Type: Blockchain
  322. AddToken(2)
  323. `
  324. tc = NewContext(common.RollupConstMaxL1UserTx)
  325. _, err = tc.GenerateBlocks(set)
  326. require.Equal(t, "Line 2: AddToken TokenID should be sequential, expected TokenID: 1, defined TokenID: 2", err.Error())
  327. set = `
  328. Type: Blockchain
  329. AddToken(1)
  330. AddToken(2)
  331. AddToken(3)
  332. AddToken(5)
  333. `
  334. tc = NewContext(common.RollupConstMaxL1UserTx)
  335. _, err = tc.GenerateBlocks(set)
  336. require.Equal(t, "Line 5: AddToken TokenID should be sequential, expected TokenID: 4, defined TokenID: 5", err.Error())
  337. // check transactions when account is not created yet
  338. set = `
  339. Type: Blockchain
  340. AddToken(1)
  341. CreateAccountDeposit(1) A: 10
  342. > batchL1
  343. CreateAccountDeposit(1) B
  344. Transfer(1) A-B: 6 (1)
  345. > batch
  346. `
  347. tc = NewContext(common.RollupConstMaxL1UserTx)
  348. _, err = tc.GenerateBlocks(set)
  349. require.Equal(t, "Line 5: CreateAccountDeposit(1)BTransfer(1) A-B: 6 (1)\n, err: Expected ':', found 'Transfer'", err.Error())
  350. set = `
  351. Type: Blockchain
  352. AddToken(1)
  353. CreateAccountDeposit(1) A: 10
  354. > batchL1
  355. CreateAccountCoordinator(1) B
  356. > batchL1
  357. > batch
  358. Transfer(1) A-B: 6 (1)
  359. > batch
  360. `
  361. tc = NewContext(common.RollupConstMaxL1UserTx)
  362. _, err = tc.GenerateBlocks(set)
  363. require.NoError(t, err)
  364. // check nonces
  365. set = `
  366. Type: Blockchain
  367. AddToken(1)
  368. CreateAccountDeposit(1) A: 10
  369. > batchL1
  370. CreateAccountCoordinator(1) B
  371. > batchL1
  372. Transfer(1) A-B: 6 (1)
  373. Transfer(1) A-B: 6 (1) // on purpose this is moving more money that what it has in the account, Til should not fail
  374. Transfer(1) B-A: 6 (1)
  375. Exit(1) A: 3 (1)
  376. > batch
  377. `
  378. tc = NewContext(common.RollupConstMaxL1UserTx)
  379. _, err = tc.GenerateBlocks(set)
  380. require.NoError(t, err)
  381. assert.Equal(t, common.Nonce(3), tc.Users["A"].Accounts[common.TokenID(1)].Nonce)
  382. assert.Equal(t, common.Idx(256), tc.Users["A"].Accounts[common.TokenID(1)].Idx)
  383. assert.Equal(t, common.Nonce(1), tc.Users["B"].Accounts[common.TokenID(1)].Nonce)
  384. assert.Equal(t, common.Idx(257), tc.Users["B"].Accounts[common.TokenID(1)].Idx)
  385. }
  386. func TestGenerateFromInstructions(t *testing.T) {
  387. // Generate block from instructions
  388. setInst := []Instruction{}
  389. i := 0
  390. setInst = append(setInst, Instruction{
  391. LineNum: i,
  392. // Literal: "AddToken(1)",
  393. Typ: TypeAddToken,
  394. TokenID: 1,
  395. })
  396. i++
  397. da := big.NewInt(10)
  398. setInst = append(setInst, Instruction{
  399. LineNum: i,
  400. // Literal: "CreateAccountDeposit(1) A: 10",
  401. Typ: common.TxTypeCreateAccountDeposit,
  402. From: "A",
  403. TokenID: 1,
  404. DepositAmount: da,
  405. })
  406. i++
  407. setInst = append(setInst, Instruction{
  408. LineNum: i,
  409. // Literal: "> batchL1",
  410. Typ: TypeNewBatchL1,
  411. })
  412. i++
  413. setInst = append(setInst, Instruction{
  414. LineNum: i,
  415. // Literal: "CreateAccountCoordinator(1) B",
  416. Typ: TxTypeCreateAccountDepositCoordinator,
  417. From: "B",
  418. TokenID: 1,
  419. })
  420. i++
  421. setInst = append(setInst, Instruction{
  422. LineNum: i,
  423. // Literal: "> batchL1",
  424. Typ: TypeNewBatchL1,
  425. })
  426. i++
  427. a := big.NewInt(6)
  428. setInst = append(setInst, Instruction{
  429. LineNum: i, // 5
  430. // Literal: "Transfer(1) A-B: 6 (1)",
  431. Typ: common.TxTypeTransfer,
  432. From: "A",
  433. To: "B",
  434. TokenID: 1,
  435. Amount: a,
  436. Fee: 1,
  437. })
  438. i++
  439. setInst = append(setInst, Instruction{
  440. LineNum: i,
  441. // Literal: "Transfer(1) A-B: 6 (1)",
  442. Typ: common.TxTypeTransfer,
  443. From: "A",
  444. To: "B",
  445. TokenID: 1,
  446. Amount: a,
  447. Fee: 1,
  448. })
  449. i++
  450. setInst = append(setInst, Instruction{
  451. LineNum: i,
  452. // Literal: "Transfer(1) B-A: 6 (1)",
  453. Typ: common.TxTypeTransfer,
  454. From: "B",
  455. To: "A",
  456. TokenID: 1,
  457. Amount: a,
  458. Fee: 1,
  459. })
  460. i++
  461. a = big.NewInt(3)
  462. setInst = append(setInst, Instruction{
  463. LineNum: i,
  464. // Literal: "Exit(1) A: 3 (1)",
  465. Typ: common.TxTypeExit,
  466. From: "A",
  467. TokenID: 1,
  468. Amount: a,
  469. Fee: 1,
  470. })
  471. i++
  472. setInst = append(setInst, Instruction{
  473. LineNum: i,
  474. // Literal: "> batch",
  475. Typ: TypeNewBatch,
  476. })
  477. setInst = append(setInst, Instruction{
  478. LineNum: i,
  479. // Literal: "> block",
  480. Typ: TypeNewBlock,
  481. })
  482. tc := NewContext(common.RollupConstMaxL1UserTx)
  483. blockFromInstructions, err := tc.GenerateBlocksFromInstructions(setInst)
  484. require.NoError(t, err)
  485. // Generate block from string
  486. setString := `
  487. Type: Blockchain
  488. AddToken(1)
  489. CreateAccountDeposit(1) A: 10
  490. > batchL1
  491. CreateAccountCoordinator(1) B
  492. > batchL1
  493. Transfer(1) A-B: 6 (1)
  494. Transfer(1) A-B: 6 (1) // on purpose this is moving more money that what it has in the account, Til should not fail
  495. Transfer(1) B-A: 6 (1)
  496. Exit(1) A: 3 (1)
  497. > batch
  498. > block
  499. `
  500. tc = NewContext(common.RollupConstMaxL1UserTx)
  501. blockFromString, err := tc.GenerateBlocks(setString)
  502. require.NoError(t, err)
  503. // Generated data should be equivalent, except for Eth Addrs and BJJs
  504. for i, strBatch := range blockFromString[0].Rollup.Batches {
  505. // instBatch := blockFromInstructions[0].Rollup.Batches[i]
  506. for j := 0; j < len(strBatch.L1CoordinatorTxs); j++ {
  507. blockFromInstructions[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromEthAddr =
  508. blockFromString[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromEthAddr
  509. blockFromInstructions[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromBJJ =
  510. blockFromString[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromBJJ
  511. }
  512. for j := 0; j < len(strBatch.L1UserTxs); j++ {
  513. blockFromInstructions[0].Rollup.Batches[i].L1UserTxs[j].FromEthAddr =
  514. blockFromString[0].Rollup.Batches[i].L1UserTxs[j].FromEthAddr
  515. blockFromInstructions[0].Rollup.Batches[i].L1UserTxs[j].FromBJJ =
  516. blockFromString[0].Rollup.Batches[i].L1UserTxs[j].FromBJJ
  517. }
  518. }
  519. for i := 0; i < len(blockFromString[0].Rollup.L1UserTxs); i++ {
  520. blockFromInstructions[0].Rollup.L1UserTxs[i].FromEthAddr =
  521. blockFromString[0].Rollup.L1UserTxs[i].FromEthAddr
  522. blockFromInstructions[0].Rollup.L1UserTxs[i].FromBJJ =
  523. blockFromString[0].Rollup.L1UserTxs[i].FromBJJ
  524. }
  525. assert.Equal(t, blockFromString, blockFromInstructions)
  526. }