Skip to content

Commit

Permalink
Merge pull request #585 from iotaledger/feat/cleanup-mock-pkg
Browse files Browse the repository at this point in the history
Cleanup mock pkg and adapt to iota.go wallet pkg
  • Loading branch information
alexsporn authored Dec 4, 2023
2 parents 73bcaa9 + b17b6a1 commit e8f363c
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 250 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/iotaledger/hive.go/stringify v0.0.0-20231128121006-331a9e522dfe
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22
github.com/iotaledger/iota.go/v4 v4.0.0-20231204084048-9c12053adaf6
github.com/labstack/echo/v4 v4.11.3
github.com/labstack/gommon v0.4.1
github.com/libp2p/go-libp2p v0.32.0
Expand All @@ -37,7 +37,6 @@ require (
github.com/prometheus/client_golang v1.17.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/wollac/iota-crypto-demo v0.0.0-20221117162917-b10619eccb98
github.com/zyedidia/generic v1.2.1
go.uber.org/atomic v1.11.0
go.uber.org/dig v1.17.1
Expand Down Expand Up @@ -161,6 +160,7 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/wollac/iota-crypto-demo v0.0.0-20221117162917-b10619eccb98 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221 h1:+ozra
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221/go.mod h1:6cLX3gnhP0WL+Q+mf3/rIqfACe5fWKVR8luPXWh2xiY=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665 h1:XdhojOpZ0t0pJFyNO0zlBogSAUrhEI67eCpTC9H6sGM=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665/go.mod h1:obK1N42oafGA7EH6zC4VX2fKh7jTa3WnIa9h1azfxq0=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22 h1:awGSiqmM1pYF+e+uILNQAiiNXrirU/mTYmUf4f/wVac=
github.com/iotaledger/iota.go/v4 v4.0.0-20231201114738-56b50084ab22/go.mod h1:aO+5iL0vTNwNfE4QMGHVIufGziSI1wTvwJY1ipSMgCk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231204084048-9c12053adaf6 h1:Wuf8Ps3tzuZ5CCbl7LA5O2qwhfuXWo30RCOT0yhm4pg=
github.com/iotaledger/iota.go/v4 v4.0.0-20231204084048-9c12053adaf6/go.mod h1:lCk9rhP3B5pX9BKhzR+Jobq4xPd+GHlqgF4Ga+eQfWA=
github.com/ipfs/boxo v0.13.1 h1:nQ5oQzcMZR3oL41REJDcTbrvDvuZh3J9ckc9+ILeRQI=
github.com/ipfs/boxo v0.13.1/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
70 changes: 0 additions & 70 deletions pkg/testsuite/mock/account.go

This file was deleted.

5 changes: 3 additions & 2 deletions pkg/testsuite/mock/block_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/iotaledger/hive.go/runtime/options"
"github.com/iotaledger/iota-core/pkg/model"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/wallet"
)

type BlockHeaderParams struct {
Expand All @@ -15,7 +16,7 @@ type BlockHeaderParams struct {
LatestFinalizedSlot *iotago.SlotIndex
IssuingTime *time.Time
ProtocolVersion *iotago.Version
Issuer Account
Issuer wallet.Account
SkipReferenceValidation bool
}
type BasicBlockParams struct {
Expand Down Expand Up @@ -86,7 +87,7 @@ func WithProtocolVersion(version iotago.Version) func(builder *BlockHeaderParams
builder.ProtocolVersion = &version
}
}
func WithIssuer(issuer Account) func(builder *BlockHeaderParams) {
func WithIssuer(issuer wallet.Account) func(builder *BlockHeaderParams) {
return func(builder *BlockHeaderParams) {
builder.Issuer = issuer
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/testsuite/mock/blockissuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter/presolidfilter"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/builder"
"github.com/iotaledger/iota.go/v4/wallet"
)

var (
Expand Down Expand Up @@ -62,7 +63,7 @@ type BlockIssuer struct {
optsRateSetterEnabled bool
}

func NewBlockIssuer(t *testing.T, name string, keyManager *KeyManager, accountID iotago.AccountID, validator bool, opts ...options.Option[BlockIssuer]) *BlockIssuer {
func NewBlockIssuer(t *testing.T, name string, keyManager *wallet.KeyManager, accountID iotago.AccountID, validator bool, opts ...options.Option[BlockIssuer]) *BlockIssuer {
priv, pub := keyManager.KeyPair()

if accountID == iotago.EmptyAccountID {
Expand Down Expand Up @@ -100,7 +101,7 @@ func (i *BlockIssuer) Shutdown() {
i.workerPool.ShutdownComplete.Wait()
}

func (i *BlockIssuer) CreateValidationBlock(ctx context.Context, alias string, issuerAccount Account, node *Node, opts ...options.Option[ValidatorBlockParams]) (*blocks.Block, error) {
func (i *BlockIssuer) CreateValidationBlock(ctx context.Context, alias string, issuerAccount wallet.Account, node *Node, opts ...options.Option[ValidatorBlockParams]) (*blocks.Block, error) {
blockParams := options.Apply(&ValidatorBlockParams{}, opts)

if blockParams.BlockHeader.IssuingTime == nil {
Expand Down Expand Up @@ -189,7 +190,7 @@ func (i *BlockIssuer) CreateValidationBlock(ctx context.Context, alias string, i
}

func (i *BlockIssuer) IssueValidationBlock(ctx context.Context, alias string, node *Node, opts ...options.Option[ValidatorBlockParams]) *blocks.Block {
block, err := i.CreateValidationBlock(ctx, alias, NewEd25519Account(i.AccountID, i.privateKey), node, opts...)
block, err := i.CreateValidationBlock(ctx, alias, wallet.NewEd25519Account(i.AccountID, i.privateKey), node, opts...)
require.NoError(i.Testing, err)

require.NoError(i.Testing, i.IssueBlock(block.ModelBlock(), node))
Expand Down Expand Up @@ -369,7 +370,7 @@ func (i *BlockIssuer) IssueBlockAndAwaitEvent(ctx context.Context, block *model.
}
}

func (i *BlockIssuer) AttachBlock(ctx context.Context, iotaBlock *iotago.Block, node *Node, optIssuerAccount ...Account) (iotago.BlockID, error) {
func (i *BlockIssuer) AttachBlock(ctx context.Context, iotaBlock *iotago.Block, node *Node, optIssuerAccount ...wallet.Account) (iotago.BlockID, error) {
// if anything changes, need to make a new signature
var resign bool

Expand Down Expand Up @@ -462,7 +463,7 @@ func (i *BlockIssuer) AttachBlock(ctx context.Context, iotaBlock *iotago.Block,
issuerAccount := optIssuerAccount[0]
iotaBlock.Header.IssuerID = issuerAccount.ID()

signature, signatureErr := iotaBlock.Sign(iotago.NewAddressKeysForEd25519Address(issuerAccount.Address().(*iotago.Ed25519Address), issuerAccount.PrivateKey()))
signature, signatureErr := iotaBlock.Sign(iotago.NewAddressKeysForEd25519Address(issuerAccount.OwnerAddress().(*iotago.Ed25519Address), issuerAccount.PrivateKey()))
if signatureErr != nil {
return iotago.EmptyBlockID, ierrors.Wrapf(ErrBlockAttacherInvalidBlock, "%w", signatureErr)
}
Expand Down Expand Up @@ -515,7 +516,7 @@ func (i *BlockIssuer) setDefaultBlockParams(blockParams *BlockHeaderParams, node
}

if blockParams.Issuer == nil {
blockParams.Issuer = NewEd25519Account(i.AccountID, i.privateKey)
blockParams.Issuer = wallet.NewEd25519Account(i.AccountID, i.privateKey)
} else if blockParams.Issuer.ID() != i.AccountID {
return ierrors.Errorf("provided issuer account %s, but issuer provided in the block params is different %s", i.AccountID, blockParams.Issuer.ID())
}
Expand Down
75 changes: 0 additions & 75 deletions pkg/testsuite/mock/keymanager.go

This file was deleted.

7 changes: 3 additions & 4 deletions pkg/testsuite/mock/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/notarization"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/merklehasher"
"github.com/iotaledger/iota.go/v4/tpkg"
"github.com/iotaledger/iota.go/v4/wallet"
)

// idAliases contains a list of aliases registered for a set of IDs.
Expand All @@ -55,7 +55,7 @@ type Node struct {

Name string
Validator *BlockIssuer
KeyManager *KeyManager
KeyManager *wallet.KeyManager

ctx context.Context
ctxCancel context.CancelFunc
Expand All @@ -82,8 +82,7 @@ type Node struct {
}

func NewNode(t *testing.T, net *Network, partition string, name string, validator bool) *Node {
seed := tpkg.RandEd25519Seed()
keyManager := NewKeyManager(seed[:], 0)
keyManager := lo.PanicOnErr(wallet.NewKeyManagerFromRandom(wallet.DefaultIOTAPath))
priv, pub := keyManager.KeyPair()

accountID := iotago.AccountID(blake2b.Sum256(pub))
Expand Down
11 changes: 5 additions & 6 deletions pkg/testsuite/mock/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/tpkg"
"github.com/iotaledger/iota.go/v4/wallet"
)

// Wallet is an object representing a wallet (similar to a FireFly wallet) capable of the following:
Expand All @@ -24,7 +24,7 @@ type Wallet struct {

Node *Node

keyManager *KeyManager
keyManager *wallet.KeyManager

BlockIssuer *BlockIssuer

Expand All @@ -33,11 +33,10 @@ type Wallet struct {
currentSlot iotago.SlotIndex
}

func NewWallet(t *testing.T, name string, node *Node, keyManager ...*KeyManager) *Wallet {
var km *KeyManager
func NewWallet(t *testing.T, name string, node *Node, keyManager ...*wallet.KeyManager) *Wallet {
var km *wallet.KeyManager
if len(keyManager) == 0 {
randomSeed := tpkg.RandEd25519Seed()
km = NewKeyManager(randomSeed[:], 0)
km = lo.PanicOnErr(wallet.NewKeyManagerFromRandom(wallet.DefaultIOTAPath))
} else {
km = keyManager[0]
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/testsuite/snapshotcreator/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine"
"github.com/iotaledger/iota-core/pkg/protocol/engine/ledger"
ledger1 "github.com/iotaledger/iota-core/pkg/protocol/engine/ledger/ledger"
"github.com/iotaledger/iota-core/pkg/testsuite/mock"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/wallet"
)

// Options stores the details about snapshots created for integration tests.
Expand All @@ -25,7 +25,7 @@ type Options struct {
RootBlocks map[iotago.BlockID]iotago.CommitmentID

// GenesisKeyManager defines the key manager used to generate keypair that can spend Genesis outputs.
GenesisKeyManager *mock.KeyManager
GenesisKeyManager *wallet.KeyManager

// Accounts defines the accounts that are created in the ledger as part of the Genesis.
Accounts []AccountDetails
Expand Down Expand Up @@ -85,7 +85,7 @@ func WithAddGenesisRootBlock(add bool) options.Option[Options] {
}

// WithGenesisKeyManager defines the seed used to generate keypair that can spend Genesis outputs.
func WithGenesisKeyManager(keyManager *mock.KeyManager) options.Option[Options] {
func WithGenesisKeyManager(keyManager *wallet.KeyManager) options.Option[Options] {
return func(m *Options) {
m.GenesisKeyManager = keyManager
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/testsuite/snapshotcreator/snapshotcreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/sybilprotection/sybilprotectionv1"
"github.com/iotaledger/iota-core/pkg/retainer/retainer"
"github.com/iotaledger/iota-core/pkg/storage"
"github.com/iotaledger/iota-core/pkg/testsuite/mock"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/wallet"
)

// CreateSnapshot creates a new snapshot. Genesis is defined by genesisTokenAmount and seedBytes, it
Expand Down Expand Up @@ -189,7 +189,7 @@ func CreateSnapshot(opts ...options.Option[Options]) error {
return engineInstance.WriteSnapshot(opt.FilePath)
}

func createGenesisOutput(api iotago.API, genesisTokenAmount iotago.BaseToken, genesisMana iotago.Mana, genesisKeyManager *mock.KeyManager) (iotago.Output, error) {
func createGenesisOutput(api iotago.API, genesisTokenAmount iotago.BaseToken, genesisMana iotago.Mana, genesisKeyManager *wallet.KeyManager) (iotago.Output, error) {
if genesisTokenAmount > 0 {
output := createOutput(genesisKeyManager.Address(iotago.AddressEd25519), genesisTokenAmount, genesisMana)

Expand Down
Loading

0 comments on commit e8f363c

Please sign in to comment.