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.

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