Skip to content

Commit

Permalink
Merge pull request #550 from iotaledger/fix/docker-network
Browse files Browse the repository at this point in the history
Fix calculation of preset values
  • Loading branch information
alexsporn authored Nov 24, 2023
2 parents a658cce + 1793ca3 commit fb7c74f
Show file tree
Hide file tree
Showing 12 changed files with 431 additions and 322 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/docker-network-health.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ name: Run Docker Network and Check Health
on:
workflow_dispatch:
pull_request:
paths-ignore:
- 'documentation/**'
- 'scripts/**'
- 'tools/**'
paths:
- '*'
- '!documentation/**'
- '!scripts/**'
- '!tools/**'
- 'tools/genesis-snapshot/**'

concurrency:
group: run-and-check-group
Expand Down
50 changes: 39 additions & 11 deletions pkg/tests/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ 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 * 10,
Amount: mock.MinIssuerAccountAmount(dummyParameters) * 10,
Mana: 0,
// AccountID is derived from this field, so this must be set uniquely for each account.
IssuerKey: oldGenesisOutputKey,
Expand Down Expand Up @@ -55,7 +58,7 @@ func Test_TransitionAndDestroyAccount(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.AddGenesisWallet("default", node1, iotago.MaxBlockIssuanceCredits/2)
wallet := ts.AddDefaultWallet(node1, iotago.MaxBlockIssuanceCredits/2)

ts.Run(true)

Expand All @@ -70,6 +73,7 @@ func Test_TransitionAndDestroyAccount(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: iotago.NewBlockIssuerKeys(oldGenesisOutputKey),
}, ts.Nodes()...)

// validator node account.
validatorAccountOutput := ts.AccountOutput("Genesis:2")
ts.AssertAccountData(&accounts.AccountData{
Expand All @@ -79,8 +83,9 @@ func Test_TransitionAndDestroyAccount(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: node1.Validator.BlockIssuerKeys(),
StakeEndEpoch: iotago.MaxEpochIndex,
ValidatorStake: mock.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount(ts.API.ProtocolParameters()),
}, ts.Nodes()...)

// default wallet block issuer account.
blockIssuerAccountOutput := ts.AccountOutput("Genesis:3")
ts.AssertAccountData(&accounts.AccountData{
Expand Down Expand Up @@ -184,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.AddGenesisWallet("default", node1, iotago.MaxBlockIssuanceCredits/2)
wallet := ts.AddDefaultWallet(node1, iotago.MaxBlockIssuanceCredits/2)

ts.Run(true)

Expand All @@ -198,8 +203,9 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: node1.Validator.BlockIssuerKeys(),
StakeEndEpoch: iotago.MaxEpochIndex,
ValidatorStake: mock.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount(ts.API.ProtocolParameters()),
}, ts.Nodes()...)

// Default wallet block issuer account.
blockIssuerAccountOutput := ts.AccountOutput("Genesis:2")
ts.AssertAccountData(&accounts.AccountData{
Expand All @@ -222,7 +228,9 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) {
ts.DefaultWallet(),
mock.WithBlockIssuerFeature(iotago.BlockIssuerKeys{newAccountBlockIssuerKey}, newAccountExpirySlot),
mock.WithStakingFeature(10000, 421, 0, 10),
mock.WithAccountAmount(mock.MinIssuerAccountAmount),
// 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())),
)

genesisCommitment := iotago.NewEmptyCommitment(ts.API)
Expand Down Expand Up @@ -359,7 +367,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.AddGenesisWallet("default", node1, iotago.MaxBlockIssuanceCredits/2)
wallet := ts.AddDefaultWallet(node1, iotago.MaxBlockIssuanceCredits/2)

ts.Run(true)

Expand All @@ -373,8 +381,9 @@ func Test_ImplicitAccounts(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: node1.Validator.BlockIssuerKeys(),
StakeEndEpoch: iotago.MaxEpochIndex,
ValidatorStake: mock.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount(ts.API.ProtocolParameters()),
}, ts.Nodes()...)

// default wallet block issuer account.
blockIssuerAccountOutput := ts.AccountOutput("Genesis:2")
ts.AssertAccountData(&accounts.AccountData{
Expand Down Expand Up @@ -403,6 +412,7 @@ func Test_ImplicitAccounts(t *testing.T) {
implicitAccountOutputID := implicitAccountOutput.OutputID()
implicitAccountID := iotago.AccountIDFromOutputID(implicitAccountOutputID)
var implicitBlockIssuerKey iotago.BlockIssuerKey = iotago.Ed25519PublicKeyHashBlockIssuerKeyFromImplicitAccountCreationAddress(newUserWallet.ImplicitAccountCreationAddress())

// the new implicit account should now be registered in the accounts ledger.
ts.AssertAccountData(&accounts.AccountData{
ID: implicitAccountID,
Expand All @@ -424,7 +434,7 @@ func Test_ImplicitAccounts(t *testing.T) {
iotago.BlockIssuerKeys{fullAccountBlockIssuerKey},
iotago.MaxSlotIndex,
),
mock.WithAccountAmount(mock.MinIssuerAccountAmount),
mock.WithAccountAmount(mock.MinIssuerAccountAmount(ts.API.ProtocolParameters())),
)
block2Commitment := node1.Protocol.MainEngineInstance().Storage.Settings().LatestCommitment().Commitment()
block2 := ts.IssueBasicBlockWithOptions("block2", newUserWallet, tx2, mock.WithStrongParents(latestParents...))
Expand All @@ -448,6 +458,7 @@ func Test_ImplicitAccounts(t *testing.T) {
FixedCostChange: 0,
DelegationStakeChange: 0,
}, false, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: implicitAccountID,
Credits: accounts.NewBlockIssuanceCredits(allotted-burned, block2Slot),
Expand Down Expand Up @@ -539,6 +550,7 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, block1Slot),
Expand Down Expand Up @@ -574,6 +586,7 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, block1Slot),
Expand Down Expand Up @@ -613,6 +626,7 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, block3Slot),
Expand Down Expand Up @@ -643,6 +657,7 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, block4Slot),
Expand Down Expand Up @@ -695,8 +710,9 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: node1.Validator.BlockIssuerKeys(),
StakeEndEpoch: iotago.MaxEpochIndex,
ValidatorStake: mock.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount(ts.API.ProtocolParameters()),
}, ts.Nodes()...)

// default wallet block issuer account.
wallet1AccountOutput := ts.AccountOutput("Genesis:2")
ts.AssertAccountData(&accounts.AccountData{
Expand All @@ -706,6 +722,7 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

wallet2AccountOutput := ts.AccountOutput("Genesis:3")
ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Expand All @@ -720,10 +737,12 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {
var block1Slot iotago.SlotIndex = 1
var latestParents []iotago.BlockID
ts.SetCurrentSlot(block1Slot)

// set the expiry of the genesis account to be the block slot + max committable age.
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 All @@ -750,6 +769,7 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, 0),
Expand Down Expand Up @@ -787,6 +807,7 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, block2Slot),
Expand Down Expand Up @@ -825,6 +846,7 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {
ExpirySlot: newExpirySlot,
BlockIssuerKeys: iotago.NewBlockIssuerKeys(wallet1.BlockIssuer.BlockIssuerKeys()[0], newWallet1IssuerKey),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, block2Slot),
Expand Down Expand Up @@ -909,8 +931,9 @@ func Test_NegativeBIC_AccountOwnedBasicOutputLocked(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: node1.Validator.BlockIssuerKeys(),
StakeEndEpoch: iotago.MaxEpochIndex,
ValidatorStake: mock.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount(ts.API.ProtocolParameters()),
}, ts.Nodes()...)

// default wallet block issuer account.
wallet1AccountOutput := ts.AccountOutput("Genesis:2")
ts.AssertAccountData(&accounts.AccountData{
Expand All @@ -920,6 +943,7 @@ func Test_NegativeBIC_AccountOwnedBasicOutputLocked(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

wallet2AccountOutput := ts.AccountOutput("Genesis:3")
ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Expand Down Expand Up @@ -971,6 +995,7 @@ func Test_NegativeBIC_AccountOwnedBasicOutputLocked(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, block1Slot),
Expand Down Expand Up @@ -1008,6 +1033,7 @@ func Test_NegativeBIC_AccountOwnedBasicOutputLocked(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, block1Slot),
Expand Down Expand Up @@ -1051,6 +1077,7 @@ func Test_NegativeBIC_AccountOwnedBasicOutputLocked(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, block3Slot),
Expand Down Expand Up @@ -1089,6 +1116,7 @@ func Test_NegativeBIC_AccountOwnedBasicOutputLocked(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
BlockIssuerKeys: wallet1.BlockIssuer.BlockIssuerKeys(),
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: wallet2.BlockIssuer.AccountID,
Credits: accounts.NewBlockIssuanceCredits(wallet2BIC, block3Slot),
Expand Down
12 changes: 6 additions & 6 deletions pkg/tests/booker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_IssuingTransactionsOutOfOrder(t *testing.T) {
defer ts.Shutdown()

node1 := ts.AddValidatorNode("node1")
wallet := ts.AddGenesisWallet("default", node1)
wallet := ts.AddDefaultWallet(node1)
ts.Run(true, map[string][]options.Option[protocol.Protocol]{})

tx1 := wallet.CreateBasicOutputsEquallyFromInput("tx1", 1, "Genesis:0")
Expand Down Expand Up @@ -55,7 +55,7 @@ func Test_WeightPropagation(t *testing.T) {
node1 := ts.AddValidatorNode("node1")
node2 := ts.AddValidatorNode("node2")

wallet := ts.AddGenesisWallet("default", node1)
wallet := ts.AddDefaultWallet(node1)

ts.Run(true, map[string][]options.Option[protocol.Protocol]{})

Expand Down Expand Up @@ -145,7 +145,7 @@ func Test_DoubleSpend(t *testing.T) {

node1 := ts.AddValidatorNode("node1")
node2 := ts.AddValidatorNode("node2")
wallet := ts.AddGenesisWallet("default", node1)
wallet := ts.AddDefaultWallet(node1)

ts.Run(true, map[string][]options.Option[protocol.Protocol]{})

Expand Down Expand Up @@ -215,7 +215,7 @@ func Test_MultipleAttachments(t *testing.T) {

nodeA := ts.AddValidatorNode("nodeA")
nodeB := ts.AddValidatorNode("nodeB")
wallet := ts.AddGenesisWallet("default", nodeA)
wallet := ts.AddDefaultWallet(nodeA)

ts.Run(true, map[string][]options.Option[protocol.Protocol]{})

Expand Down Expand Up @@ -339,7 +339,7 @@ func Test_SpendRejectedCommittedRace(t *testing.T) {

node1 := ts.AddValidatorNode("node1")
node2 := ts.AddValidatorNode("node2")
wallet := ts.AddGenesisWallet("default", node1)
wallet := ts.AddDefaultWallet(node1)

ts.Run(true, map[string][]options.Option[protocol.Protocol]{})

Expand Down Expand Up @@ -612,7 +612,7 @@ func Test_SpendPendingCommittedRace(t *testing.T) {

node1 := ts.AddValidatorNode("node1")
node2 := ts.AddValidatorNode("node2")
wallet := ts.AddGenesisWallet("default", node1)
wallet := ts.AddDefaultWallet(node1)

ts.Run(true, map[string][]options.Option[protocol.Protocol]{})

Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/committee_rotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Test_TopStakersRotation(t *testing.T) {
ts.AddValidatorNode("node4", 1_000_003)
ts.AddValidatorNode("node5", 1_000_002)
ts.AddValidatorNode("node6", 1_000_001)
ts.AddGenesisWallet("default", node1)
ts.AddDefaultWallet(node1)

ts.AddNode("node7")

Expand Down
6 changes: 3 additions & 3 deletions pkg/tests/loss_of_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestLossOfAcceptanceFromGenesis(t *testing.T) {
defer ts.Shutdown()

node0 := ts.AddValidatorNode("node0")
ts.AddGenesisWallet("default", node0)
ts.AddDefaultWallet(node0)
ts.AddValidatorNode("node1")
ts.AddNode("node2")

Expand Down Expand Up @@ -121,7 +121,7 @@ func TestLossOfAcceptanceFromSnapshot(t *testing.T) {
defer ts.Shutdown()

node0 := ts.AddValidatorNode("node0")
ts.AddGenesisWallet("default", node0)
ts.AddDefaultWallet(node0)
ts.AddValidatorNode("node1")
node2 := ts.AddNode("node2")

Expand Down Expand Up @@ -215,7 +215,7 @@ func TestLossOfAcceptanceWithRestartFromDisk(t *testing.T) {
defer ts.Shutdown()

node0 := ts.AddValidatorNode("node0")
ts.AddGenesisWallet("default", node0)
ts.AddDefaultWallet(node0)
ts.AddValidatorNode("node1")
node2 := ts.AddNode("node2")

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.AddGenesisWallet("default", node0, iotago.MaxBlockIssuanceCredits/2)
ts.AddDefaultWallet(node0, iotago.MaxBlockIssuanceCredits/2)

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.AddGenesisWallet("default", nodeA, iotago.MaxBlockIssuanceCredits/2)
ts.AddDefaultWallet(nodeA, iotago.MaxBlockIssuanceCredits/2)

nodeOptions := []options.Option[protocol.Protocol]{
protocol.WithStorageOptions(
Expand Down
Loading

0 comments on commit fb7c74f

Please sign in to comment.