Skip to content

Commit

Permalink
Merge pull request #557 from iotaledger/chore/cleanup-tests
Browse files Browse the repository at this point in the history
Cleanup tests
  • Loading branch information
muXxer authored Nov 24, 2023
2 parents 3845348 + c4264f5 commit 2585be1
Show file tree
Hide file tree
Showing 15 changed files with 616 additions and 131 deletions.
2 changes: 1 addition & 1 deletion 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-20231122112629-bdf1cc39fba7
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231123103852-bb039cbab83b
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231123103318-f6ea945e2e98
github.com/iotaledger/iota.go/v4 v4.0.0-20231124100551-bb617f46bb49
github.com/iotaledger/iota.go/v4 v4.0.0-20231124103306-ad44904e2b86
github.com/labstack/echo/v4 v4.11.3
github.com/labstack/gommon v0.4.1
github.com/libp2p/go-libp2p v0.32.0
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.20231123103852-bb039cbab83b h1:T/9f4
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231123103852-bb039cbab83b/go.mod h1:c7ktZxoH5Wp2ixzJn/8RmM5v2QOCIu/79tDFvfLbyPs=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231123103318-f6ea945e2e98 h1:PjGs+njONeFaxFgQ3lxxlRs3wTYw3233f/yDyTV8/F8=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231123103318-f6ea945e2e98/go.mod h1:jFRt2SZO3KE74/mk+zeCjlhVROriEg86K8CJTxvfdP8=
github.com/iotaledger/iota.go/v4 v4.0.0-20231124100551-bb617f46bb49 h1:xdsynMvuo1KcFCjvuUH8ekh6zigKnOj+/j/WrvHaDxU=
github.com/iotaledger/iota.go/v4 v4.0.0-20231124100551-bb617f46bb49/go.mod h1:aO+5iL0vTNwNfE4QMGHVIufGziSI1wTvwJY1ipSMgCk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231124103306-ad44904e2b86 h1:vIQemhyUKXzLtmuyadp2VAwg2lGGYciIjRIqWSMs/30=
github.com/iotaledger/iota.go/v4 v4.0.0-20231124103306-ad44904e2b86/go.mod h1:aO+5iL0vTNwNfE4QMGHVIufGziSI1wTvwJY1ipSMgCk=
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
81 changes: 47 additions & 34 deletions pkg/tests/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/accounts"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
"github.com/iotaledger/iota-core/pkg/testsuite"
"github.com/iotaledger/iota-core/pkg/testsuite/depositcalculator"
"github.com/iotaledger/iota-core/pkg/testsuite/mock"
"github.com/iotaledger/iota-core/pkg/testsuite/snapshotcreator"
"github.com/iotaledger/iota-core/pkg/utils"
Expand All @@ -19,22 +20,7 @@ import (
func Test_TransitionAndDestroyAccount(t *testing.T) {
oldGenesisOutputKey := utils.RandBlockIssuerKey()

// TODO: remove this ugly workaround
dummyParameters := iotago.NewV3ProtocolParameters(testsuite.DefaultProtocolParameterOptions("dummy")...)

ts := testsuite.NewTestSuite(t, testsuite.WithAccounts(snapshotcreator.AccountDetails{
// Nil address will be replaced with the address generated from genesis seed.
Address: nil,
// Set an amount enough to cover storage deposit and more issuer keys.
Amount: mock.MinIssuerAccountAmount(dummyParameters) * 10,
Mana: 0,
// AccountID is derived from this field, so this must be set uniquely for each account.
IssuerKey: oldGenesisOutputKey,
// Expiry Slot is the slot index at which the account expires.
ExpirySlot: iotago.MaxSlotIndex,
// BlockIssuanceCredits on this account is custom because it never needs to issue.
BlockIssuanceCredits: iotago.BlockIssuanceCredits(123),
}),
ts := testsuite.NewTestSuite(t,
testsuite.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(
0,
Expand All @@ -53,12 +39,26 @@ func Test_TransitionAndDestroyAccount(t *testing.T) {
)
defer ts.Shutdown()

ts.AddGenesisAccount(snapshotcreator.AccountDetails{
// Nil address will be replaced with the address generated from genesis seed.
Address: nil,
// Set an amount enough to cover storage deposit and more issuer keys.
Amount: mock.MinIssuerAccountAmount(ts.API.ProtocolParameters()) * 10,
Mana: 0,
// AccountID is derived from this field, so this must be set uniquely for each account.
IssuerKey: oldGenesisOutputKey,
// Expiry Slot is the slot index at which the account expires.
ExpirySlot: iotago.MaxSlotIndex,
// BlockIssuanceCredits on this account is custom because it never needs to issue.
BlockIssuanceCredits: iotago.BlockIssuanceCredits(123),
})

// Add a validator node to the network. This will add a validator account to the snapshot.
node1 := ts.AddValidatorNode("node1")
// Add a non-validator node to the network. This will not add any accounts to the snapshot.
_ = ts.AddNode("node2")
// Add a default block issuer to the network. This will add another block issuer account to the snapshot.
wallet := ts.AddDefaultWallet(node1, iotago.MaxBlockIssuanceCredits/2)
wallet := ts.AddDefaultWallet(node1)

ts.Run(true)

Expand Down Expand Up @@ -189,7 +189,7 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) {
// Add a non-validator node to the network. This will not add any accounts to the snapshot.
_ = ts.AddNode("node2")
// Add a default block issuer to the network. This will add another block issuer account to the snapshot.
wallet := ts.AddDefaultWallet(node1, iotago.MaxBlockIssuanceCredits/2)
wallet := ts.AddDefaultWallet(node1)

ts.Run(true)

Expand Down Expand Up @@ -221,16 +221,23 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) {
// set the expiry slot of the transitioned genesis account to the latest committed + MaxCommittableAge
newAccountExpirySlot := node1.Protocol.MainEngineInstance().Storage.Settings().LatestCommitment().Slot() + ts.API.ProtocolParameters().MaxCommittableAge()

stakedAmount := iotago.BaseToken(10000)

validatorAccountAmount, err := depositcalculator.MinDeposit(ts.API.ProtocolParameters(), iotago.OutputAccount,
depositcalculator.WithAddress(&iotago.Ed25519Address{}),
depositcalculator.WithBlockIssuerKeys(1),
depositcalculator.WithStakedAmount(stakedAmount),
)
require.NoError(t, err)

var block1Slot iotago.SlotIndex = 1
tx1 := ts.DefaultWallet().CreateAccountFromInput(
"TX1",
"Genesis:0",
ts.DefaultWallet(),
mock.WithBlockIssuerFeature(iotago.BlockIssuerKeys{newAccountBlockIssuerKey}, newAccountExpirySlot),
mock.WithStakingFeature(10000, 421, 0, 10),
// TODO: Temporary "fix" for the tests, lets fix this in another PR, so we can at least use the docker network again
//mock.WithAccountAmount(mock.MinIssuerAccountAmount(ts.API.ProtocolParameters())),
mock.WithAccountAmount(mock.MinValidatorAccountAmount(ts.API.ProtocolParameters())),
mock.WithStakingFeature(stakedAmount, 421, 0, 10),
mock.WithAccountAmount(validatorAccountAmount),
)

genesisCommitment := iotago.NewEmptyCommitment(ts.API)
Expand All @@ -251,7 +258,7 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) {
PreviousOutputID: iotago.EmptyOutputID,
BlockIssuerKeysAdded: iotago.NewBlockIssuerKeys(newAccountBlockIssuerKey),
BlockIssuerKeysRemoved: iotago.NewBlockIssuerKeys(),
ValidatorStakeChange: 10000,
ValidatorStakeChange: int64(stakedAmount),
StakeEndEpochChange: 10,
FixedCostChange: 421,
DelegationStakeChange: 0,
Expand All @@ -266,7 +273,7 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) {
StakeEndEpoch: 10,
FixedCost: 421,
DelegationStake: 0,
ValidatorStake: 10000,
ValidatorStake: stakedAmount,
}, ts.Nodes()...)

// CREATE DELEGATION TO NEW ACCOUNT FROM BASIC UTXO
Expand Down Expand Up @@ -305,7 +312,7 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) {
StakeEndEpoch: 10,
FixedCost: 421,
DelegationStake: iotago.BaseToken(delegatedAmount),
ValidatorStake: 10000,
ValidatorStake: stakedAmount,
}, ts.Nodes()...)

// transition a delegation output to a delayed claiming state
Expand Down Expand Up @@ -338,7 +345,7 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) {
StakeEndEpoch: 10,
FixedCost: 421,
DelegationStake: iotago.BaseToken(0),
ValidatorStake: 10000,
ValidatorStake: stakedAmount,
}, ts.Nodes()...)
}

Expand Down Expand Up @@ -367,7 +374,7 @@ func Test_ImplicitAccounts(t *testing.T) {
// Add a non-validator node to the network. This will not add any accounts to the snapshot.
_ = ts.AddNode("node2")
// Add a default block issuer to the network. This will add another block issuer account to the snapshot.
wallet := ts.AddDefaultWallet(node1, iotago.MaxBlockIssuanceCredits/2)
wallet := ts.AddDefaultWallet(node1)

ts.Run(true)

Expand Down Expand Up @@ -497,8 +504,8 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
wallet1BIC := iotago.BlockIssuanceCredits(100000)
wallet2BIC := iotago.BlockIssuanceCredits(0)

wallet1 := ts.AddGenesisWallet("wallet 1", node2, wallet1BIC)
wallet2 := ts.AddGenesisWallet("wallet 2", node2, wallet2BIC)
wallet1 := ts.AddGenesisWallet("wallet 1", node2, testsuite.WithWalletBlockIssuanceCredits(wallet1BIC))
wallet2 := ts.AddGenesisWallet("wallet 2", node2, testsuite.WithWalletBlockIssuanceCredits(wallet2BIC))

ts.Run(false)

Expand Down Expand Up @@ -694,9 +701,16 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {

wallet1BIC := iotago.BlockIssuanceCredits(-1)
wallet2BIC := iotago.MaxBlockIssuanceCredits / 2

// Add a default block issuer to the network. This will add another block issuer account to the snapshot.
wallet1 := ts.AddGenesisWallet("wallet 1", node1, wallet1BIC)
wallet2 := ts.AddGenesisWallet("wallet 2", node1, wallet2BIC)
minDeposit, err := depositcalculator.MinDeposit(ts.API.ProtocolParameters(), iotago.OutputAccount,
depositcalculator.WithAddress(&iotago.Ed25519Address{}),
depositcalculator.WithBlockIssuerKeys(2),
)
require.NoError(t, err)

wallet1 := ts.AddGenesisWallet("wallet 1", node1, testsuite.WithWalletAmount(minDeposit), testsuite.WithWalletBlockIssuanceCredits(wallet1BIC))
wallet2 := ts.AddGenesisWallet("wallet 2", node1, testsuite.WithWalletBlockIssuanceCredits(wallet2BIC))

ts.Run(true)

Expand Down Expand Up @@ -742,7 +756,6 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {
newExpirySlot := block1Slot + ts.API.ProtocolParameters().MaxCommittableAge()
{
// Prepare a transaction that will try to spend an AccountOutput of a locked account.
// BUG: How can we add a block issuer feature here with only minimum funds?
tx1 := wallet1.TransitionAccount(
"TX1",
"Genesis:2",
Expand Down Expand Up @@ -916,8 +929,8 @@ func Test_NegativeBIC_AccountOwnedBasicOutputLocked(t *testing.T) {
wallet1BIC := iotago.BlockIssuanceCredits(-1)
wallet2BIC := iotago.MaxBlockIssuanceCredits / 2
// Add a default block issuer to the network. This will add another block issuer account to the snapshot.
wallet1 := ts.AddGenesisWallet("wallet 1", node1, wallet1BIC)
wallet2 := ts.AddGenesisWallet("wallet 2", node1, wallet2BIC)
wallet1 := ts.AddGenesisWallet("wallet 1", node1, testsuite.WithWalletBlockIssuanceCredits(wallet1BIC))
wallet2 := ts.AddGenesisWallet("wallet 2", node1, testsuite.WithWalletBlockIssuanceCredits(wallet2BIC))

ts.Run(true)

Expand Down
12 changes: 6 additions & 6 deletions pkg/tests/committee_rotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func Test_TopStakersRotation(t *testing.T) {
)
defer ts.Shutdown()

node1 := ts.AddValidatorNode("node1", 1_000_006)
ts.AddValidatorNode("node2", 1_000_005)
ts.AddValidatorNode("node3", 1_000_004)
ts.AddValidatorNode("node4", 1_000_003)
ts.AddValidatorNode("node5", 1_000_002)
ts.AddValidatorNode("node6", 1_000_001)
node1 := ts.AddValidatorNode("node1", testsuite.WithWalletAmount(1_000_006))
ts.AddValidatorNode("node2", testsuite.WithWalletAmount(1_000_005))
ts.AddValidatorNode("node3", testsuite.WithWalletAmount(1_000_004))
ts.AddValidatorNode("node4", testsuite.WithWalletAmount(1_000_003))
ts.AddValidatorNode("node5", testsuite.WithWalletAmount(1_000_002))
ts.AddValidatorNode("node6", testsuite.WithWalletAmount(1_000_001))
ts.AddDefaultWallet(node1)

ts.AddNode("node7")
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/protocol_engine_switching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestProtocol_EngineSwitching(t *testing.T) {
node6 := ts.AddValidatorNode("node6")
node7 := ts.AddValidatorNode("node7")
node8 := ts.AddNode("node8")
ts.AddDefaultWallet(node0, iotago.MaxBlockIssuanceCredits/2)
ts.AddDefaultWallet(node0)

const expectedCommittedSlotAfterPartitionMerge = 19
nodesP1 := []*mock.Node{node0, node1, node2, node3, node4, node5}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/protocol_startup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func Test_StartNodeFromSnapshotAndDisk(t *testing.T) {
nodeA := ts.AddValidatorNode("nodeA")
nodeB := ts.AddValidatorNode("nodeB")
ts.AddNode("nodeC")
ts.AddDefaultWallet(nodeA, iotago.MaxBlockIssuanceCredits/2)
ts.AddDefaultWallet(nodeA)

nodeOptions := []options.Option[protocol.Protocol]{
protocol.WithStorageOptions(
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/upgrade_signaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func Test_Upgrade_Signaling(t *testing.T) {
ts.AddValidatorNode("nodeD")
ts.AddNode("nodeE")
ts.AddNode("nodeF")
wallet := ts.AddDefaultWallet(nodeA, iotago.MaxBlockIssuanceCredits/2)
wallet := ts.AddDefaultWallet(nodeA)

ts.Run(true, map[string][]options.Option[protocol.Protocol]{
"nodeA": nodeOptionsWithoutV5,
Expand Down
Loading

0 comments on commit 2585be1

Please sign in to comment.