Skip to content

Commit

Permalink
Fixes?.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Dec 21, 2023
1 parent dcfae70 commit 18b5ebd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
33 changes: 16 additions & 17 deletions integration/simulation/transaction_injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ func (ti *TransactionInjector) Start() {
})
}

wg.Go(func() error {
/*wg.Go(func() error {
ti.issueRandomTransfers()
return nil
})
})*/ //todo - fix

wg.Go(func() error {
ti.issueRandomValueTransfers()
Expand Down Expand Up @@ -219,7 +219,7 @@ func (ti *TransactionInjector) issueRandomTransfers() {
for len(ti.wallets.SimObsWallets) > 1 && fromWallet.Address().Hex() == toWallet.Address().Hex() {
toWallet = ti.rndObsWallet()
}
tx := ti.newObscuroTransferTx(fromWallet, toWallet.Address(), testcommon.RndBtw(1, 500))
tx := ti.newObscuroTransferTx(fromWallet, toWallet.Address(), testcommon.RndBtw(1, 500), testcommon.HOC)
tx = obscuroClient.EstimateGasAndGasPrice(tx)
signedTx, err := fromWallet.SignTransaction(tx)
if err != nil {
Expand Down Expand Up @@ -287,24 +287,22 @@ func (ti *TransactionInjector) bridgeRandomGasTransfers() {
func (ti *TransactionInjector) issueRandomDeposits() {
// todo (@stefan) - this implementation transfers from the hoc and poc owner contracts
// a better implementation should use the bridge
fromWalletHoc := ti.wallets.Tokens[testcommon.HOC].L2Owner
fromWalletPoc := ti.wallets.Tokens[testcommon.POC].L2Owner

for txCounter := 0; ti.shouldKeepIssuing(txCounter); txCounter++ {
fromWallet := fromWalletHoc
fromWalletToken := testcommon.HOC
if txCounter%2 == 0 {
fromWallet = fromWalletPoc
fromWalletToken = testcommon.POC
}
fromWallet := ti.wallets.Tokens[fromWalletToken].L2Owner
toWallet := ti.rndObsWallet()
obscuroClient := ti.rpcHandles.ObscuroWalletRndClient(fromWallet)
v := testcommon.RndBtw(500, 2000)
tx := ti.newObscuroTransferTx(fromWallet, toWallet.Address(), v)
tx = obscuroClient.EstimateGasAndGasPrice(tx)
txData := ti.newObscuroTransferTx(fromWallet, toWallet.Address(), v, fromWalletToken)
tx := obscuroClient.EstimateGasAndGasPrice(txData)
signedTx, err := fromWallet.SignTransaction(tx)
if err != nil {
panic(err)
}
ti.logger.Info("Deposit transaction injected into L2.", log.TxKey, signedTx.Hash(), "fromAddress", fromWallet.Address(), "toAddress", toWallet.Address())
ti.logger.Info("Deposit transaction injected into L2.", log.TxKey, signedTx.Hash(), "fromAddress", fromWallet.Address(), "toAddress", toWallet.Address())

ti.stats.Deposit(big.NewInt(int64(v)))

Expand Down Expand Up @@ -337,8 +335,9 @@ func (ti *TransactionInjector) issueInvalidL2Txs() {
for len(ti.wallets.SimObsWallets) > 1 && fromWallet.Address().Hex() == toWallet.Address().Hex() {
toWallet = ti.rndObsWallet()
}
tx := ti.newCustomObscuroWithdrawalTx(testcommon.RndBtw(1, 100))
txData := ti.newCustomObscuroWithdrawalTx(testcommon.RndBtw(1, 100))

tx := ti.rpcHandles.ObscuroWalletRndClient(fromWallet).EstimateGasAndGasPrice(txData)
signedTx := ti.createInvalidSignage(tx, fromWallet)

err := ti.rpcHandles.ObscuroWalletRndClient(fromWallet).SendTransaction(ti.ctx, signedTx)
Expand Down Expand Up @@ -368,24 +367,24 @@ func (ti *TransactionInjector) rndObsWallet() wallet.Wallet {
return ti.wallets.SimObsWallets[rand.Intn(len(ti.wallets.SimObsWallets))] //nolint:gosec
}

func (ti *TransactionInjector) newObscuroTransferTx(from wallet.Wallet, dest gethcommon.Address, amount uint64) types.TxData {
func (ti *TransactionInjector) newObscuroTransferTx(from wallet.Wallet, dest gethcommon.Address, amount uint64, ercType testcommon.ERC20) types.TxData {
data := erc20contractlib.CreateTransferTxData(dest, common.ValueInWei(big.NewInt(int64(amount))))
return ti.newTx(data, from.GetNonceAndIncrement())
return ti.newTx(data, from.GetNonceAndIncrement(), ercType)
}

func (ti *TransactionInjector) newCustomObscuroWithdrawalTx(amount uint64) types.TxData {
transferERC20data := erc20contractlib.CreateTransferTxData(testcommon.BridgeAddress, common.ValueInWei(big.NewInt(int64(amount))))
return ti.newTx(transferERC20data, 1)
return ti.newTx(transferERC20data, 1, testcommon.HOC)
}

func (ti *TransactionInjector) newTx(data []byte, nonce uint64) types.TxData {
func (ti *TransactionInjector) newTx(data []byte, nonce uint64, ercType testcommon.ERC20) types.TxData {
return &types.LegacyTx{
Nonce: nonce,
Value: gethcommon.Big0,
Gas: uint64(1_000_000),
GasPrice: gethcommon.Big1,
Data: data,
To: ti.wallets.Tokens[testcommon.HOC].L2ContractAddress,
To: ti.wallets.Tokens[ercType].L2ContractAddress,
}
}

Expand Down
2 changes: 1 addition & 1 deletion integration/simulation/transaction_injector_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (m *txInjectorTracker) trackTransferL2Tx(tx *common.L2Tx) {
func (m *txInjectorTracker) trackNativeValueTransferL2Tx(tx *common.L2Tx) {
m.l2TransactionsLock.Lock()
defer m.l2TransactionsLock.Unlock()
m.NativeValueTransferL2Transactions = append(m.TransferL2Transactions, tx)
m.NativeValueTransferL2Transactions = append(m.NativeValueTransferL2Transactions, tx)
}

// GetL1Transactions returns all generated L1 L2Txs
Expand Down
3 changes: 2 additions & 1 deletion tools/hardhatdeployer/obscuro_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ func fundDeployerWithFaucet(cfg *Config, client *obsclient.AuthObsClient, logger
}

destAddr := client.Address()
tx := &types.LegacyTx{
txData := &types.LegacyTx{
Nonce: nonce,
Value: big.NewInt(Prealloc),
Gas: uint64(1_000_000),
GasPrice: gethcommon.Big1,
To: &destAddr,
}
tx := faucetClient.EstimateGasAndGasPrice(txData)
signedTx, err := faucetWallet.SignTransaction(tx)
if err != nil {
return fmt.Errorf("failed to sign faucet transaction: %w", err)
Expand Down

0 comments on commit 18b5ebd

Please sign in to comment.