Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Nov 23, 2023
1 parent 8d01adb commit 7bddf61
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/iotaledger/iota-core/pkg/storage/prunable/slotstore"
"github.com/iotaledger/iota-core/pkg/utils"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
"github.com/iotaledger/iota.go/v4/tpkg"
)

Expand All @@ -44,7 +43,7 @@ func NewTestSuite(test *testing.T) *TestSuite {

t := &TestSuite{
T: test,
apiProvider: api.SingleVersionProvider(testAPI),
apiProvider: iotago.SingleVersionProvider(testAPI),
accounts: make(map[string]iotago.AccountID),
blockIssuerKeys: make(map[string]iotago.BlockIssuerKey),
outputs: make(map[string]iotago.OutputID),
Expand Down
9 changes: 4 additions & 5 deletions pkg/protocol/engine/accounts/mana/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/accounts"
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
"github.com/iotaledger/iota.go/v4/tpkg"
)

Expand All @@ -25,7 +24,7 @@ func TestManager_GetManaOnAccountOverflow(t *testing.T) {
switch id {
case accountIDOverflow:
return utxoledger.CreateOutput(
api.SingleVersionProvider(tpkg.TestAPI),
iotago.SingleVersionProvider(tpkg.TestAPI),
iotago.OutputIDFromTransactionIDAndIndex(iotago.NewTransactionID(0, tpkg.Rand32ByteArray()), 0),
tpkg.RandBlockID(),
tpkg.RandSlot(),
Expand All @@ -38,7 +37,7 @@ func TestManager_GetManaOnAccountOverflow(t *testing.T) {
), nil
case accountIDRecentOutput:
return utxoledger.CreateOutput(
api.SingleVersionProvider(tpkg.TestAPI),
iotago.SingleVersionProvider(tpkg.TestAPI),
iotago.OutputIDFromTransactionIDAndIndex(iotago.NewTransactionID(1, tpkg.Rand32ByteArray()), 0),
tpkg.RandBlockID(),
tpkg.RandSlot(),
Expand All @@ -51,7 +50,7 @@ func TestManager_GetManaOnAccountOverflow(t *testing.T) {
), nil
default:
return utxoledger.CreateOutput(
api.SingleVersionProvider(tpkg.TestAPI),
iotago.SingleVersionProvider(tpkg.TestAPI),
iotago.OutputIDFromTransactionIDAndIndex(iotago.NewTransactionID(0, tpkg.Rand32ByteArray()), 0),
tpkg.RandBlockID(),
tpkg.RandSlot(),
Expand Down Expand Up @@ -101,7 +100,7 @@ func TestManager_GetManaOnAccountOverflow(t *testing.T) {
}
}

manager := NewManager(api.SingleVersionProvider(tpkg.TestAPI), outputRetriever, accountRetriever)
manager := NewManager(iotago.SingleVersionProvider(tpkg.TestAPI), outputRetriever, accountRetriever)
manaDecayProvider := manager.apiProvider.LatestAPI().ManaDecayProvider()

// The value for this account will overflow because component values are too big.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/attestation/slotattestation"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
"github.com/iotaledger/iota.go/v4/builder"
)

Expand Down Expand Up @@ -78,7 +77,7 @@ func NewTestFramework(test *testing.T) *TestFramework {
),
)

t.apiProvider = api.SingleVersionProvider(t.testAPI)
t.apiProvider = iotago.SingleVersionProvider(t.testAPI)

t.Instance = slotattestation.NewManager(
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
"github.com/iotaledger/iota-core/pkg/protocol/engine/commitmentfilter"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
"github.com/iotaledger/iota.go/v4/builder"
"github.com/iotaledger/iota.go/v4/tpkg"
)
Expand Down Expand Up @@ -121,7 +120,7 @@ func TestCommitmentFilter_NoAccount(t *testing.T) {
testAPI := tpkg.TestAPI

tf := NewTestFramework(t,
api.SingleVersionProvider(testAPI),
iotago.SingleVersionProvider(testAPI),
)

tf.CommitmentFilter.events.BlockAllowed.Hook(func(block *blocks.Block) {
Expand Down Expand Up @@ -183,7 +182,7 @@ func TestCommitmentFilter_BurnedMana(t *testing.T) {
testAPI := tpkg.TestAPI

tf := NewTestFramework(t,
api.SingleVersionProvider(testAPI),
iotago.SingleVersionProvider(testAPI),
)

tf.CommitmentFilter.events.BlockAllowed.Hook(func(block *blocks.Block) {
Expand Down Expand Up @@ -231,7 +230,7 @@ func TestCommitmentFilter_Expiry(t *testing.T) {
testAPI := tpkg.TestAPI

tf := NewTestFramework(t,
api.SingleVersionProvider(testAPI),
iotago.SingleVersionProvider(testAPI),
)

tf.CommitmentFilter.events.BlockAllowed.Hook(func(block *blocks.Block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/iotaledger/iota-core/pkg/storage/prunable/epochstore"
"github.com/iotaledger/iota-core/pkg/storage/prunable/slotstore"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
"github.com/iotaledger/iota.go/v4/builder"
"github.com/iotaledger/iota.go/v4/tpkg"
)
Expand All @@ -43,7 +42,7 @@ func NewTestFramework(test *testing.T) *TestFramework {
T: test,
blocks: shrinkingmap.New[string, *blocks.Block](),

SeatManager: mock.NewManualPOA(api.SingleVersionProvider(tpkg.TestAPI), epochstore.NewStore(kvstore.Realm{}, mapdb.NewMapDB(), 0, (*account.Accounts).Bytes, account.AccountsFromBytes)),
SeatManager: mock.NewManualPOA(iotago.SingleVersionProvider(tpkg.TestAPI), epochstore.NewStore(kvstore.Realm{}, mapdb.NewMapDB(), 0, (*account.Accounts).Bytes, account.AccountsFromBytes)),
}

evictionState := eviction.NewState(mapdb.NewMapDB(), func(slot iotago.SlotIndex) (*slotstore.Store[iotago.BlockID, iotago.CommitmentID], error) {
Expand All @@ -57,7 +56,7 @@ func NewTestFramework(test *testing.T) *TestFramework {
return tpkg.TestAPI.ProtocolParameters().GenesisBlockID()
})

t.blockCache = blocks.New(evictionState, api.SingleVersionProvider(tpkg.TestAPI))
t.blockCache = blocks.New(evictionState, iotago.SingleVersionProvider(tpkg.TestAPI))
instance := thresholdblockgadget.New(t.blockCache, t.SeatManager, func(err error) {
fmt.Printf(">> Gadget.Error: %s\n", err)
})
Expand Down
3 changes: 1 addition & 2 deletions pkg/protocol/engine/eviction/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/iotaledger/iota-core/pkg/storage/database"
"github.com/iotaledger/iota-core/pkg/storage/prunable"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
"github.com/iotaledger/iota.go/v4/tpkg"
)

Expand All @@ -20,7 +19,7 @@ func TestState_RootBlocks(t *testing.T) {
prunableStorage := prunable.New(database.Config{
Engine: hivedb.EngineMapDB,
Directory: t.TempDir(),
}, api.SingleVersionProvider(tpkg.TestAPI), errorHandler)
}, iotago.SingleVersionProvider(tpkg.TestAPI), errorHandler)

ts := NewTestFramework(t, prunableStorage, eviction.NewState(mapdb.NewMapDB(), prunableStorage.RootBlocks, func() iotago.BlockID {
return tpkg.TestAPI.ProtocolParameters().GenesisBlockID()
Expand Down
9 changes: 4 additions & 5 deletions pkg/protocol/engine/filter/blockfilter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/iotaledger/iota-core/pkg/model"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
"github.com/iotaledger/iota.go/v4/builder"
"github.com/iotaledger/iota.go/v4/tpkg"
)
Expand Down Expand Up @@ -115,7 +114,7 @@ func TestFilter_WithMaxAllowedWallClockDrift(t *testing.T) {
testAPI := tpkg.TestAPI

tf := NewTestFramework(t,
api.SingleVersionProvider(testAPI),
iotago.SingleVersionProvider(testAPI),
WithMaxAllowedWallClockDrift(allowedDrift),
)

Expand All @@ -135,8 +134,8 @@ func TestFilter_WithMaxAllowedWallClockDrift(t *testing.T) {
}

func TestFilter_ProtocolVersion(t *testing.T) {
apiProvider := api.NewEpochBasedProvider(
api.WithAPIForMissingVersionCallback(
apiProvider := iotago.NewEpochBasedProvider(
iotago.WithAPIForMissingVersionCallback(
func(params iotago.ProtocolParameters) (iotago.API, error) {
return iotago.V3API(iotago.NewV3ProtocolParameters(iotago.WithVersion(params.Version()))), nil
},
Expand Down Expand Up @@ -204,7 +203,7 @@ func TestFilter_ValidationBlocks(t *testing.T) {
testAPI := tpkg.TestAPI

tf := NewTestFramework(t,
api.SingleVersionProvider(testAPI),
iotago.SingleVersionProvider(testAPI),
)

validatorAccountID := tpkg.RandAccountID()
Expand Down
7 changes: 3 additions & 4 deletions pkg/protocol/engine/mempool/v1/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/mempool/conflictdag/conflictdagv1"
mempooltests "github.com/iotaledger/iota-core/pkg/protocol/engine/mempool/tests"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
"github.com/iotaledger/iota.go/v4/tpkg"
)

Expand All @@ -44,7 +43,7 @@ func TestMempoolV1_ResourceCleanup(t *testing.T) {
conflictDAG := conflictdagv1.New[iotago.TransactionID, mempool.StateID, vote.MockedRank](func() int { return 0 })
memPoolInstance := New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] {
return ledgerState.ResolveOutputState(reference)
}, mutationsFunc, workers, conflictDAG, api.SingleVersionProvider(tpkg.TestAPI), func(error) {})
}, mutationsFunc, workers, conflictDAG, iotago.SingleVersionProvider(tpkg.TestAPI), func(error) {})

tf := mempooltests.NewTestFramework(t, memPoolInstance, conflictDAG, ledgerState, workers)

Expand Down Expand Up @@ -153,7 +152,7 @@ func newTestFramework(t *testing.T) *mempooltests.TestFramework {

return mempooltests.NewTestFramework(t, New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] {
return ledgerState.ResolveOutputState(reference)
}, mutationsFunc, workers, conflictDAG, api.SingleVersionProvider(tpkg.TestAPI), func(error) {}), conflictDAG, ledgerState, workers)
}, mutationsFunc, workers, conflictDAG, iotago.SingleVersionProvider(tpkg.TestAPI), func(error) {}), conflictDAG, ledgerState, workers)
}

func newForkingTestFramework(t *testing.T) *mempooltests.TestFramework {
Expand All @@ -168,5 +167,5 @@ func newForkingTestFramework(t *testing.T) *mempooltests.TestFramework {

return mempooltests.NewTestFramework(t, New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] {
return ledgerState.ResolveOutputState(reference)
}, mutationsFunc, workers, conflictDAG, api.SingleVersionProvider(tpkg.TestAPI), func(error) {}, WithForkAllTransactions[vote.MockedRank](true)), conflictDAG, ledgerState, workers)
}, mutationsFunc, workers, conflictDAG, iotago.SingleVersionProvider(tpkg.TestAPI), func(error) {}, WithForkAllTransactions[vote.MockedRank](true)), conflictDAG, ledgerState, workers)
}
5 changes: 2 additions & 3 deletions pkg/protocol/engine/utxoledger/iteration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger/tpkg"
"github.com/iotaledger/iota-core/pkg/utils"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
iotago_tpkg "github.com/iotaledger/iota.go/v4/tpkg"
)

func TestUTXOComputeBalance(t *testing.T) {
manager := utxoledger.New(mapdb.NewMapDB(), api.SingleVersionProvider(iotago_tpkg.TestAPI))
manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI))

initialOutput := tpkg.RandLedgerStateOutputOnAddressWithAmount(iotago.OutputBasic, utils.RandAddress(iotago.AddressEd25519), 2_134_656_365)
require.NoError(t, manager.AddGenesisUnspentOutput(initialOutput))
Expand Down Expand Up @@ -53,7 +52,7 @@ func TestUTXOComputeBalance(t *testing.T) {
}

func TestUTXOIteration(t *testing.T) {
manager := utxoledger.New(mapdb.NewMapDB(), api.SingleVersionProvider(iotago_tpkg.TestAPI))
manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI))

outputs := utxoledger.Outputs{
tpkg.RandLedgerStateOutputOnAddress(iotago.OutputBasic, utils.RandAddress(iotago.AddressEd25519)),
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocol/engine/utxoledger/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger"
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger/tpkg"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
iotago_tpkg "github.com/iotaledger/iota.go/v4/tpkg"
)

func TestConfirmationApplyAndRollbackToEmptyLedger(t *testing.T) {
manager := utxoledger.New(mapdb.NewMapDB(), api.SingleVersionProvider(iotago_tpkg.TestAPI))
manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI))

outputs := utxoledger.Outputs{
tpkg.RandLedgerStateOutputWithType(iotago.OutputBasic),
Expand Down Expand Up @@ -89,7 +88,7 @@ func TestConfirmationApplyAndRollbackToEmptyLedger(t *testing.T) {
}

func TestConfirmationApplyAndRollbackToPreviousLedger(t *testing.T) {
manager := utxoledger.New(mapdb.NewMapDB(), api.SingleVersionProvider(iotago_tpkg.TestAPI))
manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI))

previousOutputs := utxoledger.Outputs{
tpkg.RandLedgerStateOutputWithType(iotago.OutputBasic),
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocol/engine/utxoledger/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger/tpkg"
"github.com/iotaledger/iota-core/pkg/utils"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
iotago_tpkg "github.com/iotaledger/iota.go/v4/tpkg"
)

func AssertOutputUnspentAndSpentTransitions(t *testing.T, output *utxoledger.Output, spent *utxoledger.Spent) {
outputID := output.OutputID()
manager := utxoledger.New(mapdb.NewMapDB(), api.SingleVersionProvider(iotago_tpkg.TestAPI))
manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI))

require.NoError(t, manager.AddGenesisUnspentOutput(output))

Expand Down Expand Up @@ -83,7 +82,7 @@ func CreateOutputAndAssertSerialization(t *testing.T, blockID iotago.BlockID, in
require.NoError(t, err)

iotagoAPI := iotago_tpkg.TestAPI
output := utxoledger.CreateOutput(api.SingleVersionProvider(iotagoAPI), outputID, blockID, indexBooked, iotaOutput, outputProof)
output := utxoledger.CreateOutput(iotago.SingleVersionProvider(iotagoAPI), outputID, blockID, indexBooked, iotaOutput, outputProof)
outputBytes, err := iotagoAPI.Encode(output.Output())
require.NoError(t, err)
proofBytes, err := outputProof.Bytes()
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocol/engine/utxoledger/slot_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger/tpkg"
"github.com/iotaledger/iota-core/pkg/utils"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
iotago_tpkg "github.com/iotaledger/iota.go/v4/tpkg"
)

Expand All @@ -40,7 +39,7 @@ func TestSimpleSlotDiffSerialization(t *testing.T) {
outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0)
require.NoError(t, err)

output := utxoledger.CreateOutput(api.SingleVersionProvider(iotago_tpkg.TestAPI), outputID, blockID, indexBooked, iotaOutput, outputProof)
output := utxoledger.CreateOutput(iotago.SingleVersionProvider(iotago_tpkg.TestAPI), outputID, blockID, indexBooked, iotaOutput, outputProof)

transactionIDSpent := utils.RandTransactionID()

Expand All @@ -65,7 +64,7 @@ func TestSimpleSlotDiffSerialization(t *testing.T) {
}

func TestSlotDiffSerialization(t *testing.T) {
manager := utxoledger.New(mapdb.NewMapDB(), api.SingleVersionProvider(iotago_tpkg.TestAPI))
manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI))

outputs := utxoledger.Outputs{
tpkg.RandLedgerStateOutputWithType(iotago.OutputBasic),
Expand Down
Loading

0 comments on commit 7bddf61

Please sign in to comment.