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.

574 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(0, 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(0, 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(0, 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(0), poolL2Txs[0].Nonce)
  197. assert.Equal(t, common.Nonce(0), poolL2Txs[1].Nonce)
  198. assert.Equal(t, common.Nonce(0), poolL2Txs[2].Nonce)
  199. assert.Equal(t, common.Nonce(1), poolL2Txs[3].Nonce)
  200. assert.Equal(t, common.Nonce(0), poolL2Txs[4].Nonce)
  201. assert.Equal(t, common.Nonce(0), poolL2Txs[5].Nonce)
  202. assert.Equal(t, common.Nonce(0), poolL2Txs[6].Nonce)
  203. assert.Equal(t, common.Nonce(0), poolL2Txs[7].Nonce)
  204. assert.Equal(t, common.Nonce(2), poolL2Txs[8].Nonce)
  205. assert.Equal(t, common.Nonce(3), poolL2Txs[9].Nonce)
  206. assert.Equal(t, tc.Users["B"].Addr.Hex(), poolL2Txs[9].ToEthAddr.Hex())
  207. assert.Equal(t, common.EmptyBJJComp, poolL2Txs[9].ToBJJ)
  208. assert.Equal(t, common.TxTypeTransferToEthAddr, poolL2Txs[9].Type)
  209. assert.Equal(t, common.FFAddr, poolL2Txs[10].ToEthAddr)
  210. assert.Equal(t, tc.Users["B"].BJJ.Public().String(), poolL2Txs[10].ToBJJ.String())
  211. assert.Equal(t, common.TxTypeTransferToBJJ, poolL2Txs[10].Type)
  212. // load another set in the same Context
  213. set = `
  214. Type: PoolL2
  215. PoolTransfer(1) A-B: 6 (1)
  216. PoolTransfer(1) B-C: 3 (1)
  217. PoolTransfer(1) A-C: 3 (1)
  218. `
  219. poolL2Txs, err = tc.GeneratePoolL2Txs(set)
  220. require.NoError(t, err)
  221. assert.Equal(t, common.Nonce(5), poolL2Txs[0].Nonce)
  222. assert.Equal(t, common.Nonce(1), poolL2Txs[1].Nonce)
  223. assert.Equal(t, common.Nonce(6), poolL2Txs[2].Nonce)
  224. // check that a PoolL2Tx can be done to a non existing ToIdx
  225. set = `
  226. Type: Blockchain
  227. AddToken(1)
  228. CreateAccountDeposit(1) A: 10
  229. > batchL1
  230. > batchL1
  231. > block
  232. `
  233. tc = NewContext(0, common.RollupConstMaxL1UserTx)
  234. _, err = tc.GenerateBlocks(set)
  235. require.NoError(t, err)
  236. set = `
  237. Type: PoolL2
  238. PoolTransferToEthAddr(1) A-B: 3 (1)
  239. PoolTransferToBJJ(1) A-C: 3 (1)
  240. `
  241. _, err = tc.GeneratePoolL2Txs(set)
  242. require.NoError(t, err)
  243. // expect error, as FromIdx=B is still not created for TokenID=1
  244. set = `
  245. Type: PoolL2
  246. PoolTransferToEthAddr(1) B-A: 3 (1)
  247. PoolTransferToBJJ(1) B-A: 3 (1)
  248. `
  249. _, err = tc.GeneratePoolL2Txs(set)
  250. require.NotNil(t, err)
  251. }
  252. func TestGeneratePoolL2TxsFromInstructions(t *testing.T) {
  253. // Generate necessary L1 data
  254. set := `
  255. Type: Blockchain
  256. AddToken(1)
  257. CreateAccountCoordinator(1) A
  258. CreateAccountDeposit(1) B: 7
  259. > batchL1
  260. > batchL1
  261. `
  262. tc := NewContext(0, common.RollupConstMaxL1UserTx)
  263. _, err := tc.GenerateBlocks(set)
  264. require.NoError(t, err)
  265. // Generate Pool txs using instructions
  266. instructionSet := []Instruction{}
  267. i := 0
  268. a := big.NewInt(3)
  269. instructionSet = append(instructionSet, Instruction{
  270. LineNum: i,
  271. // Literal: "PoolTransferToEthAddr(1) B-A: 3 (1)",
  272. Typ: common.TxTypeTransferToEthAddr,
  273. From: "B",
  274. To: "A",
  275. TokenID: 1,
  276. Amount: a,
  277. Fee: 1,
  278. })
  279. i++
  280. instructionSet = append(instructionSet, Instruction{
  281. LineNum: i,
  282. // Literal: "PoolTransferToBJJ(1) B-A: 3 (1)",
  283. Typ: common.TxTypeTransferToBJJ,
  284. From: "B",
  285. To: "A",
  286. TokenID: 1,
  287. Amount: a,
  288. Fee: 1,
  289. })
  290. txsFromInstructions, err := tc.GeneratePoolL2TxsFromInstructions(instructionSet)
  291. require.NoError(t, err)
  292. // Generate Pool txs using string
  293. tc = NewContext(0, common.RollupConstMaxL1UserTx)
  294. _, err = tc.GenerateBlocks(set)
  295. require.NoError(t, err)
  296. stringSet := `
  297. Type: PoolL2
  298. PoolTransferToEthAddr(1) B-A: 3 (1)
  299. PoolTransferToBJJ(1) B-A: 3 (1)
  300. `
  301. txsFromString, err := tc.GeneratePoolL2Txs(stringSet)
  302. require.NoError(t, err)
  303. // Compare generated txs from instructions and string
  304. // timestamps will be different
  305. for i := 0; i < len(txsFromString); i++ {
  306. txsFromInstructions[i].Timestamp = txsFromString[i].Timestamp
  307. }
  308. assert.Equal(t, txsFromString, txsFromInstructions)
  309. }
  310. func TestGenerateErrors(t *testing.T) {
  311. // unregistered token
  312. set := `Type: Blockchain
  313. CreateAccountDeposit(1) A: 5
  314. > batchL1
  315. `
  316. tc := NewContext(0, common.RollupConstMaxL1UserTx)
  317. _, err := tc.GenerateBlocks(set)
  318. assert.Equal(t, "Line 2: Can not process CreateAccountDeposit: TokenID 1 not registered, last registered TokenID: 0", err.Error())
  319. // ensure AddToken sequentiality and not using 0
  320. set = `
  321. Type: Blockchain
  322. AddToken(0)
  323. `
  324. tc = NewContext(0, common.RollupConstMaxL1UserTx)
  325. _, err = tc.GenerateBlocks(set)
  326. require.Equal(t, "Line 2: AddToken can not register TokenID 0", err.Error())
  327. set = `
  328. Type: Blockchain
  329. AddToken(2)
  330. `
  331. tc = NewContext(0, common.RollupConstMaxL1UserTx)
  332. _, err = tc.GenerateBlocks(set)
  333. require.Equal(t, "Line 2: AddToken TokenID should be sequential, expected TokenID: 1, defined TokenID: 2", err.Error())
  334. set = `
  335. Type: Blockchain
  336. AddToken(1)
  337. AddToken(2)
  338. AddToken(3)
  339. AddToken(5)
  340. `
  341. tc = NewContext(0, common.RollupConstMaxL1UserTx)
  342. _, err = tc.GenerateBlocks(set)
  343. require.Equal(t, "Line 5: AddToken TokenID should be sequential, expected TokenID: 4, defined TokenID: 5", err.Error())
  344. // check transactions when account is not created yet
  345. set = `
  346. Type: Blockchain
  347. AddToken(1)
  348. CreateAccountDeposit(1) A: 10
  349. > batchL1
  350. CreateAccountDeposit(1) B
  351. Transfer(1) A-B: 6 (1)
  352. > batch
  353. `
  354. tc = NewContext(0, common.RollupConstMaxL1UserTx)
  355. _, err = tc.GenerateBlocks(set)
  356. require.Equal(t, "Line 5: CreateAccountDeposit(1)BTransfer(1) A-B: 6 (1)\n, err: Expected ':', found 'Transfer'", err.Error())
  357. set = `
  358. Type: Blockchain
  359. AddToken(1)
  360. CreateAccountDeposit(1) A: 10
  361. > batchL1
  362. CreateAccountCoordinator(1) B
  363. > batchL1
  364. > batch
  365. Transfer(1) A-B: 6 (1)
  366. > batch
  367. `
  368. tc = NewContext(0, common.RollupConstMaxL1UserTx)
  369. _, err = tc.GenerateBlocks(set)
  370. require.NoError(t, err)
  371. // check nonces
  372. set = `
  373. Type: Blockchain
  374. AddToken(1)
  375. CreateAccountDeposit(1) A: 10
  376. > batchL1
  377. CreateAccountCoordinator(1) B
  378. > batchL1
  379. Transfer(1) A-B: 6 (1)
  380. Transfer(1) A-B: 6 (1) // on purpose this is moving more money that what it has in the account, Til should not fail
  381. Transfer(1) B-A: 6 (1)
  382. Exit(1) A: 3 (1)
  383. > batch
  384. `
  385. tc = NewContext(0, common.RollupConstMaxL1UserTx)
  386. _, err = tc.GenerateBlocks(set)
  387. require.NoError(t, err)
  388. assert.Equal(t, common.Nonce(3), tc.Users["A"].Accounts[common.TokenID(1)].Nonce)
  389. assert.Equal(t, common.Idx(256), tc.Users["A"].Accounts[common.TokenID(1)].Idx)
  390. assert.Equal(t, common.Nonce(1), tc.Users["B"].Accounts[common.TokenID(1)].Nonce)
  391. assert.Equal(t, common.Idx(257), tc.Users["B"].Accounts[common.TokenID(1)].Idx)
  392. }
  393. func TestGenerateFromInstructions(t *testing.T) {
  394. // Generate block from instructions
  395. setInst := []Instruction{}
  396. i := 0
  397. setInst = append(setInst, Instruction{
  398. LineNum: i,
  399. // Literal: "AddToken(1)",
  400. Typ: TypeAddToken,
  401. TokenID: 1,
  402. })
  403. i++
  404. da := big.NewInt(10)
  405. setInst = append(setInst, Instruction{
  406. LineNum: i,
  407. // Literal: "CreateAccountDeposit(1) A: 10",
  408. Typ: common.TxTypeCreateAccountDeposit,
  409. From: "A",
  410. TokenID: 1,
  411. DepositAmount: da,
  412. })
  413. i++
  414. setInst = append(setInst, Instruction{
  415. LineNum: i,
  416. // Literal: "> batchL1",
  417. Typ: TypeNewBatchL1,
  418. })
  419. i++
  420. setInst = append(setInst, Instruction{
  421. LineNum: i,
  422. // Literal: "CreateAccountCoordinator(1) B",
  423. Typ: TxTypeCreateAccountDepositCoordinator,
  424. From: "B",
  425. TokenID: 1,
  426. })
  427. i++
  428. setInst = append(setInst, Instruction{
  429. LineNum: i,
  430. // Literal: "> batchL1",
  431. Typ: TypeNewBatchL1,
  432. })
  433. i++
  434. a := big.NewInt(6)
  435. setInst = append(setInst, Instruction{
  436. LineNum: i, // 5
  437. // Literal: "Transfer(1) A-B: 6 (1)",
  438. Typ: common.TxTypeTransfer,
  439. From: "A",
  440. To: "B",
  441. TokenID: 1,
  442. Amount: a,
  443. Fee: 1,
  444. })
  445. i++
  446. setInst = append(setInst, Instruction{
  447. LineNum: i,
  448. // Literal: "Transfer(1) A-B: 6 (1)",
  449. Typ: common.TxTypeTransfer,
  450. From: "A",
  451. To: "B",
  452. TokenID: 1,
  453. Amount: a,
  454. Fee: 1,
  455. })
  456. i++
  457. setInst = append(setInst, Instruction{
  458. LineNum: i,
  459. // Literal: "Transfer(1) B-A: 6 (1)",
  460. Typ: common.TxTypeTransfer,
  461. From: "B",
  462. To: "A",
  463. TokenID: 1,
  464. Amount: a,
  465. Fee: 1,
  466. })
  467. i++
  468. a = big.NewInt(3)
  469. setInst = append(setInst, Instruction{
  470. LineNum: i,
  471. // Literal: "Exit(1) A: 3 (1)",
  472. Typ: common.TxTypeExit,
  473. From: "A",
  474. TokenID: 1,
  475. Amount: a,
  476. Fee: 1,
  477. })
  478. i++
  479. setInst = append(setInst, Instruction{
  480. LineNum: i,
  481. // Literal: "> batch",
  482. Typ: TypeNewBatch,
  483. })
  484. setInst = append(setInst, Instruction{
  485. LineNum: i,
  486. // Literal: "> block",
  487. Typ: TypeNewBlock,
  488. })
  489. tc := NewContext(0, common.RollupConstMaxL1UserTx)
  490. blockFromInstructions, err := tc.GenerateBlocksFromInstructions(setInst)
  491. require.NoError(t, err)
  492. // Generate block from string
  493. setString := `
  494. Type: Blockchain
  495. AddToken(1)
  496. CreateAccountDeposit(1) A: 10
  497. > batchL1
  498. CreateAccountCoordinator(1) B
  499. > batchL1
  500. Transfer(1) A-B: 6 (1)
  501. Transfer(1) A-B: 6 (1) // on purpose this is moving more money that what it has in the account, Til should not fail
  502. Transfer(1) B-A: 6 (1)
  503. Exit(1) A: 3 (1)
  504. > batch
  505. > block
  506. `
  507. tc = NewContext(0, common.RollupConstMaxL1UserTx)
  508. blockFromString, err := tc.GenerateBlocks(setString)
  509. require.NoError(t, err)
  510. // Generated data should be equivalent, except for Eth Addrs and BJJs
  511. for i, strBatch := range blockFromString[0].Rollup.Batches {
  512. // instBatch := blockFromInstructions[0].Rollup.Batches[i]
  513. for j := 0; j < len(strBatch.L1CoordinatorTxs); j++ {
  514. blockFromInstructions[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromEthAddr =
  515. blockFromString[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromEthAddr
  516. blockFromInstructions[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromBJJ =
  517. blockFromString[0].Rollup.Batches[i].L1CoordinatorTxs[j].FromBJJ
  518. }
  519. for j := 0; j < len(strBatch.L1UserTxs); j++ {
  520. blockFromInstructions[0].Rollup.Batches[i].L1UserTxs[j].FromEthAddr =
  521. blockFromString[0].Rollup.Batches[i].L1UserTxs[j].FromEthAddr
  522. blockFromInstructions[0].Rollup.Batches[i].L1UserTxs[j].FromBJJ =
  523. blockFromString[0].Rollup.Batches[i].L1UserTxs[j].FromBJJ
  524. }
  525. }
  526. for i := 0; i < len(blockFromString[0].Rollup.L1UserTxs); i++ {
  527. blockFromInstructions[0].Rollup.L1UserTxs[i].FromEthAddr =
  528. blockFromString[0].Rollup.L1UserTxs[i].FromEthAddr
  529. blockFromInstructions[0].Rollup.L1UserTxs[i].FromBJJ =
  530. blockFromString[0].Rollup.L1UserTxs[i].FromBJJ
  531. }
  532. assert.Equal(t, blockFromString, blockFromInstructions)
  533. }