Skip to content

Commit

Permalink
Merge pull request #1 from iotaledger/feat/cleanup
Browse files Browse the repository at this point in the history
Test CI setup and cleanup old unused code
  • Loading branch information
daria305 authored Oct 26, 2023
2 parents 3086f4d + e2d8108 commit 63d7510
Show file tree
Hide file tree
Showing 28 changed files with 156 additions and 897 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
build:
name: Build evil-tools
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: self-hosted
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
golangci-lint:
name: GolangCI-Lint
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
Expand Down
29 changes: 16 additions & 13 deletions accountwallet/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/iotaledger/iota.go/v4/builder"
)

// CreateAccount creates an implicit account and immediatelly transition it to a regular account.
// CreateAccount creates an implicit account and immediately transition it to a regular account.
func (a *AccountWallet) CreateAccount(params *CreateAccountParams) (iotago.AccountID, error) {
if params.Implicit {
return a.createAccountImplicitly(params)
Expand All @@ -23,7 +23,7 @@ func (a *AccountWallet) CreateAccount(params *CreateAccountParams) (iotago.Accou

func (a *AccountWallet) createAccountImplicitly(params *CreateAccountParams) (iotago.AccountID, error) {
// An implicit account has an implicitly defined Block Issuer Key, corresponding to the address itself.
// Thus implicit accounts can issue blocks by signing them with the private key corresponding to the public key
// Thus, implicit accounts can issue blocks by signing them with the private key corresponding to the public key
// from which the Implicit Account Creation Address was derived.
implicitAccountOutput, privateKey, err := a.getFunds(params.Amount, iotago.AddressImplicitAccountCreation)
if err != nil {
Expand All @@ -39,7 +39,12 @@ func (a *AccountWallet) createAccountImplicitly(params *CreateAccountParams) (io

log.Debugf("Transitioning implicit account with implicitAccountID %s for alias %s to regular account", params.Alias, iotago.AccountIDFromOutputID(implicitAccountOutput.OutputID).ToHex())

implicitAccAddr := iotago.ImplicitAccountCreationAddressFromPubKey(privateKey.Public().(ed25519.PublicKey))
pubKey, isEd25519 := privateKey.Public().(ed25519.PublicKey)
if !isEd25519 {
return iotago.EmptyAccountID, ierrors.New("Failed to create account: only Ed25519 keys are supported")
}

implicitAccAddr := iotago.ImplicitAccountCreationAddressFromPubKey(pubKey)
addrKeys := iotago.NewAddressKeysForImplicitAccountCreationAddress(implicitAccAddr, privateKey)
implicitBlockIssuerKey := iotago.Ed25519PublicKeyHashBlockIssuerKeyFromImplicitAccountCreationAddress(implicitAccAddr)
blockIssuerKeys := iotago.NewBlockIssuerKeys(implicitBlockIssuerKey)
Expand All @@ -52,7 +57,7 @@ func (a *AccountWallet) transitionImplicitAccount(
implicitAccAddr *iotago.ImplicitAccountCreationAddress,
accAddr iotago.Address,
blockIssuerKeys iotago.BlockIssuerKeys,
privateKey ed25519.PrivateKey,
_ ed25519.PrivateKey,
params *CreateAccountParams,
) (iotago.AccountID, error) {
// transition from implicit to regular account
Expand All @@ -62,12 +67,10 @@ func (a *AccountWallet) transitionImplicitAccount(
BlockIssuer(blockIssuerKeys, iotago.MaxSlotIndex).MustBuild()

log.Infof("Created account %s with %d tokens\n", accountOutput.AccountID.ToHex(), params.Amount)
txBuilder, err := a.createTransactionBuilder(implicitAccountOutput, implicitAccAddr, accountOutput)
if err != nil {
return iotago.EmptyAccountID, ierrors.Wrap(err, "Failed to create account")
}
txBuilder := a.createTransactionBuilder(implicitAccountOutput, implicitAccAddr, accountOutput)

// TODO get congestionResponse from API
var rmc iotago.Mana = 0
var rmc iotago.Mana
var implicitAccountID iotago.AccountID
txBuilder.AllotRequiredManaAndStoreRemainingManaInOutput(txBuilder.CreationSlot(), rmc, implicitAccountID, 0)

Expand All @@ -79,7 +82,7 @@ func (a *AccountWallet) transitionImplicitAccount(
return iotago.EmptyAccountID, nil
}

func (a *AccountWallet) createAccountWithFaucet(params *CreateAccountParams) (iotago.AccountID, error) {
func (a *AccountWallet) createAccountWithFaucet(_ *CreateAccountParams) (iotago.AccountID, error) {
log.Debug("Not implemented yet")
//faucetOutput := a.getFaucetOutput()
//
Expand All @@ -94,7 +97,7 @@ func (a *AccountWallet) createAccountWithFaucet(params *CreateAccountParams) (io
return iotago.EmptyAccountID, nil
}

func (a *AccountWallet) createTransactionBuilder(input *models.Output, address iotago.Address, accountOutput *iotago.AccountOutput) (*builder.TransactionBuilder, error) {
func (a *AccountWallet) createTransactionBuilder(input *models.Output, address iotago.Address, accountOutput *iotago.AccountOutput) *builder.TransactionBuilder {
currentTime := time.Now()
currentSlot := a.client.LatestAPI().TimeProvider().SlotFromTime(currentTime)

Expand All @@ -109,7 +112,7 @@ func (a *AccountWallet) createTransactionBuilder(input *models.Output, address i
txBuilder.AddOutput(accountOutput)
txBuilder.SetCreationSlot(currentSlot)

return txBuilder, nil
return txBuilder
}

func (a *AccountWallet) getAddress(addressType iotago.AddressType) (iotago.DirectUnlockableAddress, ed25519.PrivateKey, uint64) {
Expand Down Expand Up @@ -139,6 +142,6 @@ func (a *AccountWallet) ListAccount() error {
return nil
}

func (a *AccountWallet) AllotToAccount(params *AllotAccountParams) error {
func (a *AccountWallet) AllotToAccount(_ *AllotAccountParams) error {
return nil
}
7 changes: 4 additions & 3 deletions accountwallet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type AccountOperation int
const (
OperationCreateAccount AccountOperation = iota
OperationConvertAccount
OperationDestroyAccound
OperationDestroyAccount
OperationAllotAccount
OperationDelegateAccount
OperationStakeAccount
Expand Down Expand Up @@ -58,6 +58,7 @@ func AvailableCommands(cmd string) bool {
}

_, ok := availableCommands[cmd]

return ok
}

Expand All @@ -66,7 +67,7 @@ type Configuration struct {
AccountStatesFile string `json:"accountStatesFile,omitempty"`
GenesisSeed string `json:"genesisSeed,omitempty"`
BlockIssuerPrivateKey string `json:"blockIssuerPrivateKey,omitempty"`
AccountID string `json:"accountID,omitempty"`
AccountID string `json:"accountId,omitempty"`
}

var accountConfigFile = "config.json"
Expand Down Expand Up @@ -150,7 +151,7 @@ type DestroyAccountParams struct {
}

func (d *DestroyAccountParams) Type() AccountOperation {
return OperationDestroyAccound
return OperationDestroyAccount
}

type AllotAccountParams struct {
Expand Down
12 changes: 8 additions & 4 deletions accountwallet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func newFaucet(clt models.Client, faucetParams *faucetParams) (*faucet, error) {
return nil, ierrors.Wrap(err, "failed to get faucet output from indexer")
}

//nolint:all,forcetypassert
f.unspentOutput = &models.Output{
Address: faucetAddr.(*iotago.Ed25519Address),
AddressIndex: 0,
Expand Down Expand Up @@ -203,12 +204,12 @@ func (f *faucet) prepareFaucetRequest(receiveAddr iotago.Address, amount iotago.
return nil, err
}

rmcAllotedTxBuilder := txBuilder.Clone()
rmcAllottedTxBuilder := txBuilder.Clone()
// faucet will allot exact mana to be burnt, rest of the mana is alloted to faucet output remainder
rmcAllotedTxBuilder.AllotRequiredManaAndStoreRemainingManaInOutput(txBuilder.CreationSlot(), rmc, f.account.ID(), remainderIndex)
rmcAllottedTxBuilder.AllotRequiredManaAndStoreRemainingManaInOutput(txBuilder.CreationSlot(), rmc, f.account.ID(), remainderIndex)

var signedTx *iotago.SignedTransaction
signedTx, err = rmcAllotedTxBuilder.Build(f.genesisHdWallet.AddressSigner())
signedTx, err = rmcAllottedTxBuilder.Build(f.genesisHdWallet.AddressSigner())
if err != nil {
log.Infof("WARN: failed to build tx with min required mana allotted, genesis potential mana was not enough, fallback to faucet account")
txBuilder.AllotAllMana(txBuilder.CreationSlot(), f.account.ID())
Expand All @@ -218,6 +219,7 @@ func (f *faucet) prepareFaucetRequest(receiveAddr iotago.Address, amount iotago.
}

// set remainder output to be reused by the Faucet wallet
//nolint:all,forcetypassert
f.unspentOutput = &models.Output{
OutputID: iotago.OutputIDFromTransactionIDAndIndex(lo.PanicOnErr(signedTx.Transaction.ID()), uint16(remainderIndex)),
Address: f.genesisHdWallet.Address(iotago.AddressEd25519).(*iotago.Ed25519Address),
Expand All @@ -236,6 +238,7 @@ func (f *faucet) createFaucetTransactionNoManaHandling(receiveAddr iotago.Addres
apiForSlot := f.clt.APIForSlot(currentSlot)
txBuilder := builder.NewTransactionBuilder(apiForSlot)

//nolint:all,forcetypassert
txBuilder.AddInput(&builder.TxInput{
UnlockTarget: f.genesisHdWallet.Address(iotago.AddressEd25519).(*iotago.Ed25519Address),
InputID: f.unspentOutput.OutputID,
Expand All @@ -244,7 +247,7 @@ func (f *faucet) createFaucetTransactionNoManaHandling(receiveAddr iotago.Addres

remainderAmount, err := safemath.SafeSub(f.unspentOutput.Balance, amount)
if err != nil {
panic(err)
return nil, 0, ierrors.Errorf("safeSub failed %d - %d: %s", f.unspentOutput.Balance, amount, err)
}

txBuilder.AddOutput(&iotago.BasicOutput{
Expand All @@ -257,6 +260,7 @@ func (f *faucet) createFaucetTransactionNoManaHandling(receiveAddr iotago.Addres

// remainder output
remainderIndex := 1
//nolint:all,forcetypassert
txBuilder.AddOutput(&iotago.BasicOutput{
Amount: remainderAmount,
Conditions: iotago.BasicOutputUnlockConditions{
Expand Down
6 changes: 5 additions & 1 deletion accountwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (a *AccountWallet) fromAccountStateFile() error {
if !os.IsNotExist(err) {
return ierrors.Wrap(err, "failed to read file")
}

return nil
}

Expand Down Expand Up @@ -174,6 +175,7 @@ func (a *AccountWallet) fromAccountStateFile() error {
return nil
}

//nolint:all,unused
func (a *AccountWallet) registerAccount(alias string, outputID iotago.OutputID, index uint64, privKey ed25519.PrivateKey) iotago.AccountID {
a.accountAliasesMutex.Lock()
defer a.accountAliasesMutex.Unlock()
Expand Down Expand Up @@ -259,7 +261,7 @@ func (a *AccountWallet) isAccountReady(accData *models.AccountData) bool {
}

if resp.Commitment.Slot >= creationSlot {
log.Infof("Slot %d commited, account %s is ready to use", creationSlot, accData.Alias)
log.Infof("Slot %d committed, account %s is ready to use", creationSlot, accData.Alias)
return true, nil
}

Expand Down Expand Up @@ -311,6 +313,7 @@ func (a *AccountWallet) destroyAccount(alias string) error {
})

// send all tokens to faucet
//nolint:all,forcetypassert
txBuilder.AddOutput(&iotago.BasicOutput{
Amount: accountOutput.BaseTokenAmount(),
Conditions: iotago.BasicOutputUnlockConditions{
Expand All @@ -337,6 +340,7 @@ func (a *AccountWallet) destroyAccount(alias string) error {
delete(a.accountsAliases, alias)

log.Infof("Account %s has been destroyed", alias)

return nil
}

Expand Down
27 changes: 2 additions & 25 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import (
"github.com/iotaledger/evil-tools/spammer"
)

// Nodes used during the test, use at least two nodes to be able to doublespend.
// Nodes used during the test, use at least two nodes to be able to double spend.
var (
// urls = []string{"http://bootstrap-01.feature.shimmer.iota.cafe:8080", "http://vanilla-01.feature.shimmer.iota.cafe:8080", "http://drng-01.feature.shimmer.iota.cafe:8080"}
urls = []string{"http://localhost:8080", "http://localhost:8090"} //, "http://localhost:8070", "http://localhost:8040"}
//urls = []string{}
)

var (
Script = "basic"
Subcommand = ""
Script = ScriptSpammer

customSpamParams = programs.CustomSpamParams{
ClientURLs: urls,
Expand All @@ -35,26 +33,5 @@ var (
AccountAlias: accountwallet.FaucetAccountAlias,
}

quickTestParams = programs.QuickTestParams{
ClientURLs: urls,
Rate: 100,
Duration: time.Second * 30,
TimeUnit: time.Second,
DelayBetweenConflicts: 0,
EnableRateSetter: false,
}

accountsSubcommandsFlags []accountwallet.AccountSubcommands

//nolint:godot
// commitmentsSpamParams = CommitmentsSpamParams{
// Rate: 1,
// Duration: time.Second * 20,
// TimeUnit: time.Second,
// NetworkAlias: "docker",
// SpammerAlias: "validator-1",
// ValidAlias: accountwallet.FaucetAccountAlias,
// CommitmentType: "latest",
// ForkAfter: 10,
// }
)
4 changes: 2 additions & 2 deletions evilwallet/evilscenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ func NewEvilScenario(options ...ScenarioOption) *EvilScenario {
option(scenario)
}
scenario.ID = base58.Encode([]byte(fmt.Sprintf("%v%v%v", scenario.ConflictBatch, scenario.Reuse, scenario.OutputWallet.ID)))[:11]
scenario.NumOfClientsNeeded = calculateNumofClientsNeeded(scenario)
scenario.NumOfClientsNeeded = calculateNumOfClientsNeeded(scenario)

return scenario
}

func calculateNumofClientsNeeded(scenario *EvilScenario) (counter int) {
func calculateNumOfClientsNeeded(scenario *EvilScenario) (counter int) {
for _, conflictMap := range scenario.ConflictBatch {
if len(conflictMap) > counter {
counter = len(conflictMap)
Expand Down
Loading

0 comments on commit 63d7510

Please sign in to comment.