Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waiting for receipt in simulation tests. #1571

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions integration/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,34 +145,34 @@ func (s *Simulation) bridgeFundingToObscuro() {
panic(err)
}

transactions := make(types.Transactions, 0)
for idx, w := range wallets {
opts, err := bind.NewKeyedTransactorWithChainID(w.PrivateKey(), w.ChainID())
if err != nil {
panic(err)
}
opts.Value = value

_, err = busCtr.SendValueToL2(opts, receivers[idx], value)
tx, err := busCtr.SendValueToL2(opts, receivers[idx], value)
if err != nil {
panic(err)
}
transactions = append(transactions, tx)
}

time.Sleep(15 * time.Second)
// todo - fix the wait group, for whatever reason it does not find a receipt...
/*wg := sync.WaitGroup{}
wg := sync.WaitGroup{}
for _, tx := range transactions {
wg.Add(1)
transaction := tx
go func() {
defer wg.Done()
err := testcommon.AwaitReceiptEth(s.ctx, s.RPCHandles.RndEthClient(), transaction.Hash(), 20*time.Second)
_, err := testcommon.AwaitReceiptEth(context.Background(), s.RPCHandles.RndEthClient().EthClient(), transaction.Hash(), 2*time.Minute)
if err != nil {
panic(err)
}
}()
}
wg.Wait()*/
wg.Wait()
Comment on lines +148 to +175
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of panic for error handling in the bridgeFundingToObscuro function is not ideal for production code. Consider using error returns and handling them gracefully to avoid crashing the entire application.

- panic(err)
+ // Handle error without panicking
+ return fmt.Errorf("error while sending value to L2: %w", err)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
transactions := make(types.Transactions, 0)
for idx, w := range wallets {
opts, err := bind.NewKeyedTransactorWithChainID(w.PrivateKey(), w.ChainID())
if err != nil {
panic(err)
}
opts.Value = value
_, err = busCtr.SendValueToL2(opts, receivers[idx], value)
tx, err := busCtr.SendValueToL2(opts, receivers[idx], value)
if err != nil {
panic(err)
}
transactions = append(transactions, tx)
}
time.Sleep(15 * time.Second)
// todo - fix the wait group, for whatever reason it does not find a receipt...
/*wg := sync.WaitGroup{}
wg := sync.WaitGroup{}
for _, tx := range transactions {
wg.Add(1)
transaction := tx
go func() {
defer wg.Done()
err := testcommon.AwaitReceiptEth(s.ctx, s.RPCHandles.RndEthClient(), transaction.Hash(), 20*time.Second)
_, err := testcommon.AwaitReceiptEth(context.Background(), s.RPCHandles.RndEthClient().EthClient(), transaction.Hash(), 2*time.Minute)
if err != nil {
panic(err)
}
}()
}
wg.Wait()*/
wg.Wait()
transactions := make(types.Transactions, 0)
for idx, w := range wallets {
opts, err := bind.NewKeyedTransactorWithChainID(w.PrivateKey(), w.ChainID())
if err != nil {
// Handle error without panicking
return fmt.Errorf("error while creating transactor: %w", err)
}
opts.Value = value
tx, err := busCtr.SendValueToL2(opts, receivers[idx], value)
if err != nil {
// Handle error without panicking
return fmt.Errorf("error while sending value to L2: %w", err)
}
transactions = append(transactions, tx)
}
wg := sync.WaitGroup{}
for _, tx := range transactions {
wg.Add(1)
transaction := tx
go func() {
defer wg.Done()
_, err := testcommon.AwaitReceiptEth(context.Background(), s.RPCHandles.RndEthClient().EthClient(), transaction.Hash(), 2*time.Minute)
if err != nil {
// Handle error without panicking
return fmt.Errorf("error while waiting for receipt: %w", err)
}
}()
}
wg.Wait()

The bridgeFundingToObscuro function's use of panic for error handling is not ideal. Consider using error returns and handling them gracefully to avoid crashing the entire application.

- panic(err)
+ // Handle error without panicking
+ return fmt.Errorf("error while sending value to L2: %w", err)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
transactions := make(types.Transactions, 0)
for idx, w := range wallets {
opts, err := bind.NewKeyedTransactorWithChainID(w.PrivateKey(), w.ChainID())
if err != nil {
panic(err)
}
opts.Value = value
_, err = busCtr.SendValueToL2(opts, receivers[idx], value)
tx, err := busCtr.SendValueToL2(opts, receivers[idx], value)
if err != nil {
panic(err)
}
transactions = append(transactions, tx)
}
time.Sleep(15 * time.Second)
// todo - fix the wait group, for whatever reason it does not find a receipt...
/*wg := sync.WaitGroup{}
wg := sync.WaitGroup{}
for _, tx := range transactions {
wg.Add(1)
transaction := tx
go func() {
defer wg.Done()
err := testcommon.AwaitReceiptEth(s.ctx, s.RPCHandles.RndEthClient(), transaction.Hash(), 20*time.Second)
_, err := testcommon.AwaitReceiptEth(context.Background(), s.RPCHandles.RndEthClient().EthClient(), transaction.Hash(), 2*time.Minute)
if err != nil {
panic(err)
}
}()
}
wg.Wait()*/
wg.Wait()
transactions := make(types.Transactions, 0)
for idx, w := range wallets {
opts, err := bind.NewKeyedTransactorWithChainID(w.PrivateKey(), w.ChainID())
if err != nil {
// Handle error without panicking
return fmt.Errorf("error while sending value to L2: %w", err)
}
opts.Value = value
tx, err := busCtr.SendValueToL2(opts, receivers[idx], value)
if err != nil {
// Handle error without panicking
return fmt.Errorf("error while sending value to L2: %w", err)
}
transactions = append(transactions, tx)
}
wg := sync.WaitGroup{}
for _, tx := range transactions {
wg.Add(1)
transaction := tx
go func() {
defer wg.Done()
_, err := testcommon.AwaitReceiptEth(context.Background(), s.RPCHandles.RndEthClient().EthClient(), transaction.Hash(), 2*time.Minute)
if err != nil {
// Handle error without panicking
return fmt.Errorf("error while sending value to L2: %w", err)
}
}()
}
wg.Wait()

}

// We subscribe to logs on every client for every wallet.
Expand Down
Loading