Skip to content

Commit

Permalink
Add depositcalculator to calculate the correct min deposits in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Nov 24, 2023
1 parent 58c27ac commit 1fd223b
Show file tree
Hide file tree
Showing 9 changed files with 374 additions and 64 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
29 changes: 21 additions & 8 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 Down Expand Up @@ -220,15 +221,22 @@ 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()

validatorAccountAmount := mock.MinValidatorAccountAmount(ts.API.ProtocolParameters())
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(validatorAccountAmount, 421, 0, 10), // match amount and staked amount to simplify the tests
mock.WithStakingFeature(stakedAmount, 421, 0, 10), // match amount and staked amount to simplify the tests
mock.WithAccountAmount(validatorAccountAmount),
)

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

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

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

Expand Down Expand Up @@ -695,8 +703,13 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {
wallet2BIC := iotago.MaxBlockIssuanceCredits / 2

// Add a default block issuer to the network. This will add another block issuer account to the snapshot.
// TODO: calculate the correct amount
wallet1 := ts.AddGenesisWallet("wallet 1", node1, testsuite.WithWalletAmount(5000000), testsuite.WithWalletBlockIssuanceCredits(wallet1BIC))
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
Loading

0 comments on commit 1fd223b

Please sign in to comment.