Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrm50 committed Sep 28, 2023
1 parent be58d07 commit 2208fd8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions components/dashboard/jsonresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func NewOutputID(outputID iotago.OutputID) *OutputID {
// }

// // NewOutputMetadata returns the OutputMetadata from the given mempool.OutputMetadata.
// func NewOutputMetadata(outputMetadata *mempool.OutputMetadata, confirmedConsumerID utxo.SignedTransactionID) *OutputMetadata {
// func NewOutputMetadata(outputMetadata *mempool.OutputMetadata, confirmedConsumerID utxo.TransactionID) *OutputMetadata {
// return &OutputMetadata{
// OutputID: NewOutputID(outputMetadata.ID()),
// ConflictIDs: lo.Map(lo.Map(outputMetadata.ConflictIDs().Slice(), func(t utxo.SignedTransactionID) []byte {
// ConflictIDs: lo.Map(lo.Map(outputMetadata.ConflictIDs().Slice(), func(t utxo.TransactionID) []byte {
// return lo.PanicOnErr(t.Bytes())
// }), base58.Encode),
// FirstConsumer: outputMetadata.FirstConsumer().Base58(),
Expand Down
20 changes: 10 additions & 10 deletions pkg/testsuite/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ import (
iotago "github.com/iotaledger/iota.go/v4"
)

func (t *TestSuite) AssertTransaction(transaction *iotago.SignedTransaction, node *mock.Node) mempool.Transaction {
var loadedTransaction mempool.TransactionMetadata
transactionID, err := transaction.ID()
func (t *TestSuite) AssertTransaction(signedTransaction *iotago.SignedTransaction, node *mock.Node) mempool.Transaction {
var loadedTransactionMetadata mempool.TransactionMetadata
signedTransactionID, err := signedTransaction.ID()
require.NoError(t.Testing, err)

t.Eventually(func() error {
var exists bool
loadedTransaction, exists = node.Protocol.MainEngineInstance().Ledger.TransactionMetadata(transactionID)
loadedTransactionMetadata, exists = node.Protocol.MainEngineInstance().Ledger.TransactionMetadata(signedTransactionID)
if !exists {
return ierrors.Errorf("AssertTransaction: %s: transaction %s does not exist", node.Name, transactionID)
return ierrors.Errorf("AssertTransaction: %s: signedTransaction %s does not exist", node.Name, signedTransactionID)
}

if transactionID != loadedTransaction.ID() {
return ierrors.Errorf("AssertTransaction: %s: expected ID %s, got %s", node.Name, transactionID, loadedTransaction.ID())
if signedTransactionID != loadedTransactionMetadata.ID() {
return ierrors.Errorf("AssertTransaction: %s: expected ID %s, got %s", node.Name, signedTransactionID, loadedTransactionMetadata.ID())
}

//nolint: forcetypeassert // we are in a test and want to assert it anyway
if !cmp.Equal(transaction.Transaction, loadedTransaction.Transaction().(*iotago.SignedTransaction).Transaction) {
return ierrors.Errorf("AssertTransaction: %s: expected %s, got %s", node.Name, transaction, loadedTransaction.Transaction())
if !cmp.Equal(signedTransaction.Transaction, loadedTransactionMetadata.Transaction().(*iotago.SignedTransaction).Transaction) {
return ierrors.Errorf("AssertTransaction: %s: expected %s, got %s", node.Name, signedTransaction, loadedTransactionMetadata.Transaction())
}

return nil
})

return loadedTransaction.Transaction()
return loadedTransactionMetadata.Transaction()
}

func (t *TestSuite) AssertTransactionsExist(transactions []*iotago.SignedTransaction, expectedExist bool, nodes ...*mock.Node) {
Expand Down
12 changes: 6 additions & 6 deletions tools/evil-spammer/spammer/spammer.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,24 +224,24 @@ func (s *Spammer) StopSpamming() {

// PostTransaction use provided client to issue a transaction. It chooses API method based on Spammer options. Counts errors,
// counts transactions and provides debug logs.
func (s *Spammer) PostTransaction(tx *iotago.SignedTransaction, clt wallet.Client) {
if tx == nil {
func (s *Spammer) PostTransaction(signedTx *iotago.SignedTransaction, clt wallet.Client) {
if signedTx == nil {
s.log.Debug(ErrTransactionIsNil)
s.ErrCounter.CountError(ErrTransactionIsNil)

return
}

txID := lo.PanicOnErr(tx.ID())
allSolid := s.handleSolidityForReuseOutputs(clt, tx)
txID := lo.PanicOnErr(signedTx.ID())
allSolid := s.handleSolidityForReuseOutputs(clt, signedTx)
if !allSolid {
s.log.Debug(ErrInputsNotSolid)
s.ErrCounter.CountError(ierrors.Wrapf(ErrInputsNotSolid, "txID: %s", txID.ToHex()))

return
}

blockID, err := clt.PostTransaction(tx)
blockID, err := clt.PostTransaction(signedTx)
if err != nil {
s.log.Debug(ierrors.Wrapf(ErrFailPostTransaction, err.Error()))
s.ErrCounter.CountError(ierrors.Wrapf(ErrFailPostTransaction, err.Error()))
Expand All @@ -250,7 +250,7 @@ func (s *Spammer) PostTransaction(tx *iotago.SignedTransaction, clt wallet.Clien
}
if s.EvilScenario.OutputWallet.Type() == wallet.Reuse {
var outputIDs iotago.OutputIDs
for index := range tx.Transaction.Outputs {
for index := range signedTx.Transaction.Outputs {
outputIDs = append(outputIDs, iotago.OutputIDFromTransactionIDAndIndex(txID, uint16(index)))
}
s.EvilWallet.SetTxOutputsSolid(outputIDs, clt.URL())
Expand Down
46 changes: 23 additions & 23 deletions tools/evil-spammer/wallet/evilwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,27 +291,27 @@ func (e *EvilWallet) requestFaucetFunds(wallet *Wallet) (outputID *Output, err e
txBuilder.AddTaggedDataPayload(&iotago.TaggedData{Tag: []byte("faucet funds"), Data: []byte("to addr" + receiveAddr.String())})
txBuilder.SetCreationSlot(clt.CurrentAPI().TimeProvider().SlotFromTime(time.Now()))

tx, err := txBuilder.Build(e.faucet.AddressSigner(faucetAddr))
signedTx, err := txBuilder.Build(e.faucet.AddressSigner(faucetAddr))
if err != nil {
return nil, err
}

// send transaction
_, err = clt.PostTransaction(tx)
_, err = clt.PostTransaction(signedTx)
if err != nil {
return nil, err
}

// requested output to split and use in spammer
output := e.outputManager.CreateOutputFromAddress(wallet, receiveAddr, faucetTokensPerRequest, iotago.OutputIDFromTransactionIDAndIndex(lo.PanicOnErr(tx.ID()), 0), tx.Transaction.Outputs[0])
output := e.outputManager.CreateOutputFromAddress(wallet, receiveAddr, faucetTokensPerRequest, iotago.OutputIDFromTransactionIDAndIndex(lo.PanicOnErr(signedTx.ID()), 0), signedTx.Transaction.Outputs[0])

// set remainder output to be reused by the faucet wallet
e.faucet.AddUnspentOutput(&Output{
OutputID: iotago.OutputIDFromTransactionIDAndIndex(lo.PanicOnErr(tx.ID()), 1),
OutputID: iotago.OutputIDFromTransactionIDAndIndex(lo.PanicOnErr(signedTx.ID()), 1),
Address: faucetAddr,
Index: 0,
Balance: tx.Transaction.Outputs[1].BaseTokenAmount(),
OutputStruct: tx.Transaction.Outputs[1],
Balance: signedTx.Transaction.Outputs[1].BaseTokenAmount(),
OutputStruct: signedTx.Transaction.Outputs[1],
})

return output, nil
Expand All @@ -325,18 +325,18 @@ func (e *EvilWallet) splitOutputs(splitOutput *Output, inputWallet, outputWallet

input, outputs := e.handleInputOutputDuringSplitOutputs(splitOutput, FaucetRequestSplitNumber, outputWallet)

tx, err := e.CreateTransaction(WithInputs(input), WithOutputs(outputs), WithIssuer(inputWallet), WithOutputWallet(outputWallet))
signedTx, err := e.CreateTransaction(WithInputs(input), WithOutputs(outputs), WithIssuer(inputWallet), WithOutputWallet(outputWallet))
if err != nil {
return iotago.TransactionID{}, err
}

_, err = e.connector.GetClient().PostTransaction(tx)
_, err = e.connector.GetClient().PostTransaction(signedTx)
if err != nil {
fmt.Println(err)
return iotago.TransactionID{}, err
}

return lo.PanicOnErr(tx.ID()), nil
return lo.PanicOnErr(signedTx.ID()), nil
}

func (e *EvilWallet) handleInputOutputDuringSplitOutputs(splitOutput *Output, splitNumber int, receiveWallet *Wallet) (input *Output, outputs []*OutputOption) {
Expand Down Expand Up @@ -396,9 +396,9 @@ func (e *EvilWallet) SendCustomConflicts(conflictsMaps []ConflictSlice) (err err
wg := sync.WaitGroup{}
for i, tx := range txs {
wg.Add(1)
go func(clt Client, tx *iotago.SignedTransaction) {
go func(clt Client, signedTx *iotago.SignedTransaction) {
defer wg.Done()
_, _ = clt.PostTransaction(tx)
_, _ = clt.PostTransaction(signedTx)
}(clients[i], tx)
}
wg.Wait()
Expand All @@ -414,7 +414,7 @@ func (e *EvilWallet) SendCustomConflicts(conflictsMaps []ConflictSlice) (err err
// Inputs of the transaction are determined in three ways:
// 1 - inputs are provided directly without associated alias, 2- alias is provided, and input is already stored in an alias manager,
// 3 - alias is provided, and there are no inputs assigned in Alias manager, so aliases are assigned to next ready inputs from input wallet.
func (e *EvilWallet) CreateTransaction(options ...Option) (tx *iotago.SignedTransaction, err error) {
func (e *EvilWallet) CreateTransaction(options ...Option) (signedTx *iotago.SignedTransaction, err error) {
buildOptions, err := NewOptions(options...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -445,23 +445,23 @@ func (e *EvilWallet) CreateTransaction(options ...Option) (tx *iotago.SignedTran
}
}

tx, err = e.makeTransaction(inputs, outputs, buildOptions.inputWallet)
signedTx, err = e.makeTransaction(inputs, outputs, buildOptions.inputWallet)
if err != nil {
return nil, err
}

e.addOutputsToOutputManager(tx, buildOptions.outputWallet, tempWallet, tempAddresses)
e.registerOutputAliases(tx, addrAliasMap)
e.addOutputsToOutputManager(signedTx, buildOptions.outputWallet, tempWallet, tempAddresses)
e.registerOutputAliases(signedTx, addrAliasMap)

return
}

// addOutputsToOutputManager adds output to the OutputManager if.
func (e *EvilWallet) addOutputsToOutputManager(tx *iotago.SignedTransaction, outWallet, tmpWallet *Wallet, tempAddresses map[string]types.Empty) {
for idx, o := range tx.Transaction.Outputs {
func (e *EvilWallet) addOutputsToOutputManager(signedTx *iotago.SignedTransaction, outWallet, tmpWallet *Wallet, tempAddresses map[string]types.Empty) {
for idx, o := range signedTx.Transaction.Outputs {
addr := o.UnlockConditionSet().Address().Address
out := &Output{
OutputID: iotago.OutputIDFromTransactionIDAndIndex(lo.PanicOnErr(tx.ID()), uint16(idx)),
OutputID: iotago.OutputIDFromTransactionIDAndIndex(lo.PanicOnErr(signedTx.ID()), uint16(idx)),
Address: addr,
Balance: o.BaseTokenAmount(),
OutputStruct: o,
Expand Down Expand Up @@ -498,13 +498,13 @@ func (e *EvilWallet) updateInputWallet(buildOptions *Options) error {
return nil
}

func (e *EvilWallet) registerOutputAliases(tx *iotago.SignedTransaction, addrAliasMap map[string]string) {
func (e *EvilWallet) registerOutputAliases(signedTx *iotago.SignedTransaction, addrAliasMap map[string]string) {
if len(addrAliasMap) == 0 {
return
}

for idx := range tx.Transaction.Outputs {
id := iotago.OutputIDFromTransactionIDAndIndex(lo.PanicOnErr(tx.ID()), uint16(idx))
for idx := range signedTx.Transaction.Outputs {
id := iotago.OutputIDFromTransactionIDAndIndex(lo.PanicOnErr(signedTx.ID()), uint16(idx))
out := e.outputManager.GetOutput(id)

// register output alias
Expand Down Expand Up @@ -741,9 +741,9 @@ func (e *EvilWallet) makeTransaction(inputs []*Output, outputs iotago.Outputs[io
return txBuilder.Build(iotago.NewInMemoryAddressSigner(walletKeys...))
}

func (e *EvilWallet) PrepareCustomConflictsSpam(scenario *EvilScenario) (txs [][]*iotago.SignedTransaction, allAliases ScenarioAlias, err error) {
func (e *EvilWallet) PrepareCustomConflictsSpam(scenario *EvilScenario) (signedTxs [][]*iotago.SignedTransaction, allAliases ScenarioAlias, err error) {
conflicts, allAliases := e.prepareConflictSliceForScenario(scenario)
txs, err = e.PrepareCustomConflicts(conflicts)
signedTxs, err = e.PrepareCustomConflicts(conflicts)

return
}
Expand Down

0 comments on commit 2208fd8

Please sign in to comment.