Skip to content

Commit

Permalink
Merge pull request #957 from iotaledger/fix/dockertests
Browse files Browse the repository at this point in the history
Fix docker network tests
  • Loading branch information
muXxer authored May 7, 2024
2 parents 1197777 + b1afe51 commit ed4f829
Show file tree
Hide file tree
Showing 36 changed files with 2,016 additions and 1,739 deletions.
5 changes: 2 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ linters:
- errchkjson
- errname
- errorlint
- execinquery
#- exhaustive
#- exhaustruct
- exportloopref
Expand All @@ -77,7 +76,7 @@ linters:
#- gocyclo
- godot
#- godox
- goerr113
- err113
- gofmt
#- gofumpt
- goheader
Expand All @@ -92,7 +91,7 @@ linters:
- importas
- inamedparam
#- interfacebloat
#- intrange # TODO: re-enable after https://github.com/ckaznocha/intrange v0.1.2 release is merged in golangci-lint
- intrange
#- ireturn
#- lll
- loggercheck
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/iotaledger/hive.go/stringify v0.0.0-20240425095808-113b21573349
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240425100742-5c85b6d16701
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240425100432-05e1bf8fc089
github.com/iotaledger/iota.go/v4 v4.0.0-20240425100055-540c74851d65
github.com/iotaledger/iota.go/v4 v4.0.0-20240503105040-c86882e71808
github.com/labstack/echo/v4 v4.12.0
github.com/labstack/gommon v0.4.2
github.com/libp2p/go-libp2p v0.33.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240425100432-05e1bf8fc089 h1:+NRPSb
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240425100432-05e1bf8fc089/go.mod h1:+iSOmdi7LSd1pXMThZsQk4YDbCSlvVomJUqbRhp3+Nk=
github.com/iotaledger/iota-crypto-demo v0.0.0-20240419094816-40260bb800f7 h1:R7ogCKTQ2D5SfVoE6n9GQUsKwm4dcxqwnU863JVlVbw=
github.com/iotaledger/iota-crypto-demo v0.0.0-20240419094816-40260bb800f7/go.mod h1:ntqq5J5Fu2SijiqPsjjdFkMm96UhGU/K0z3j6ARpHec=
github.com/iotaledger/iota.go/v4 v4.0.0-20240425100055-540c74851d65 h1:cKn39WbYZrBbGIeK5SZyu1Eukh1IOq8ZdBh7jC2/9Gg=
github.com/iotaledger/iota.go/v4 v4.0.0-20240425100055-540c74851d65/go.mod h1:2/gBFmGlXzZLcpOqTQTl2GqXtoe/aec6Fu9QTooQPZQ=
github.com/iotaledger/iota.go/v4 v4.0.0-20240503105040-c86882e71808 h1:ruI9Xk8g4xbCFsXBBvIXkOi03WprGJyHkmERGSizFTk=
github.com/iotaledger/iota.go/v4 v4.0.0-20240503105040-c86882e71808/go.mod h1:2/gBFmGlXzZLcpOqTQTl2GqXtoe/aec6Fu9QTooQPZQ=
github.com/ipfs/boxo v0.19.0 h1:UbX9FBJQF19ACLqRZOgdEla6jR/sC4H1O+iGE0NToXA=
github.com/ipfs/boxo v0.19.0/go.mod h1:V5gJzbIMwKEXrg3IdvAxIdF7UPgU4RsXmNGS8MQ/0D4=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/account_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (d *AccountDiff) String() string {
builder.AddField(stringify.NewStructField("PreviousExpirySlot", uint32(d.PreviousExpirySlot)))
builder.AddField(stringify.NewStructField("NewOutputID", d.NewOutputID))
builder.AddField(stringify.NewStructField("PreviousOutputID", d.PreviousOutputID))
builder.AddField(stringify.NewStructField("BlockIssuerKeysAdded", func() string { return strconv.Itoa(d.BlockIssuerKeysAdded.Size()) }()))
builder.AddField(stringify.NewStructField("BlockIssuerKeysRemoved", func() string { return strconv.Itoa(d.BlockIssuerKeysRemoved.Size()) }()))
builder.AddField(stringify.NewStructField("BlockIssuerKeysAdded", func() string { return strconv.Itoa(len(d.BlockIssuerKeysAdded)) }()))
builder.AddField(stringify.NewStructField("BlockIssuerKeysRemoved", func() string { return strconv.Itoa(len(d.BlockIssuerKeysRemoved)) }()))
builder.AddField(stringify.NewStructField("ValidatorStakeChange", d.ValidatorStakeChange))
builder.AddField(stringify.NewStructField("DelegationStakeChange", d.DelegationStakeChange))
builder.AddField(stringify.NewStructField("FixedCostChange", d.FixedCostChange))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (s *Scheduler) removeIssuer(issuerID iotago.AccountID, err error) {
return true
})

for i := 0; i < q.readyHeap.Len(); i++ {
for i := range q.readyHeap.Len() {
block := q.readyHeap[i].Value
block.SetDropped()
s.events.BlockDropped.Trigger(block, err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/protocol/engine/ledger/ledger/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func (v *VM) ValidateSignatures(signedTransaction mempool.SignedTransaction, res
}

apiForSlot := v.ledger.apiProvider.APIForSlot(commitmentInput.Slot)
futureBoundedSlotIndex := commitmentInput.Slot + apiForSlot.ProtocolParameters().MinCommittableAge()
claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex)
futureBoundedSlot := commitmentInput.Slot + apiForSlot.ProtocolParameters().MinCommittableAge()
claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlot)

reward, _, _, rewardErr := v.ledger.sybilProtection.ValidatorReward(accountID, stakingFeature, claimingEpoch)
if rewardErr != nil {
Expand All @@ -141,8 +141,8 @@ func (v *VM) ValidateSignatures(signedTransaction mempool.SignedTransaction, res
delegationEnd := castOutput.EndEpoch

apiForSlot := v.ledger.apiProvider.APIForSlot(commitmentInput.Slot)
futureBoundedSlotIndex := commitmentInput.Slot + apiForSlot.ProtocolParameters().MinCommittableAge()
claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex)
futureBoundedSlot := commitmentInput.Slot + apiForSlot.ProtocolParameters().MinCommittableAge()
claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlot)

if delegationID.Empty() {
delegationID = iotago.DelegationIDFromOutputID(outputID)
Expand Down
8 changes: 4 additions & 4 deletions pkg/requesthandler/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ func (r *RequestHandler) RewardsByOutputID(outputID iotago.OutputID, optSlot ...
//nolint:forcetypeassert
stakingFeature := feature.(*iotago.StakingFeature)

futureBoundedSlotIndex := slot + apiForSlot.ProtocolParameters().MinCommittableAge()
claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex)
futureBoundedSlot := slot + apiForSlot.ProtocolParameters().MinCommittableAge()
claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlot)

stakingPoolValidatorAccountID = accountOutput.AccountID
// check if the account is a validator
Expand All @@ -185,8 +185,8 @@ func (r *RequestHandler) RewardsByOutputID(outputID iotago.OutputID, optSlot ...
//nolint:forcetypeassert
delegationOutput := utxoOutput.Output().(*iotago.DelegationOutput)
delegationEnd := delegationOutput.EndEpoch
futureBoundedSlotIndex := slot + apiForSlot.ProtocolParameters().MinCommittableAge()
claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex)
futureBoundedSlot := slot + apiForSlot.ProtocolParameters().MinCommittableAge()
claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlot)

// If Delegation ID is zeroed, the output is in delegating state, which means its End Epoch is not set and we must use the
// "last epoch" for the rewards calculation.
Expand Down
10 changes: 5 additions & 5 deletions pkg/tests/reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ func Test_Delegation_DelayedClaimingDestroyOutputWithoutRewards(t *testing.T) {
latestCommitment := blockIssuanceInfo.LatestCommitment
apiForSlot := ts.DefaultWallet().Client.APIForSlot(block1_2Slot)

futureBoundedSlotIndex := latestCommitment.Slot + apiForSlot.ProtocolParameters().MinCommittableAge()
futureBoundedEpochIndex := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex)
futureBoundedSlot := latestCommitment.Slot + apiForSlot.ProtocolParameters().MinCommittableAge()
futureBoundedEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlot)

registrationSlot := apiForSlot.TimeProvider().EpochEnd(apiForSlot.TimeProvider().EpochFromSlot(block1_2Slot))
delegationEndEpoch := futureBoundedEpochIndex
if futureBoundedSlotIndex > registrationSlot {
delegationEndEpoch = futureBoundedEpochIndex + 1
delegationEndEpoch := futureBoundedEpoch
if futureBoundedSlot > registrationSlot {
delegationEndEpoch = futureBoundedEpoch + 1
}

tx2 := ts.DefaultWallet().DelayedClaimingTransition("TX2", ts.DefaultWallet().OutputData("TX1:0"), delegationEndEpoch)
Expand Down
50 changes: 33 additions & 17 deletions pkg/testsuite/mock/wallet_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/hive.go/runtime/options"
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"
"github.com/iotaledger/iota.go/v4/vm"
Expand Down Expand Up @@ -136,34 +137,43 @@ func (w *Wallet) CreateDelegationFromInput(transactionName string, input *Output
return signedTransaction
}

func (w *Wallet) StakingStartEpochFromSlot(latestCommitmentSlot iotago.SlotIndex) iotago.EpochIndex {
apiForSlot := w.Client.APIForSlot(latestCommitmentSlot)

pastBoundedSlot := latestCommitmentSlot + apiForSlot.ProtocolParameters().MaxCommittableAge()
pastBoundedEpoch := apiForSlot.TimeProvider().EpochFromSlot(pastBoundedSlot)

return pastBoundedEpoch
}

func (w *Wallet) DelegationStartFromSlot(slot, latestCommitmentSlot iotago.SlotIndex) iotago.EpochIndex {
apiForSlot := w.Client.APIForSlot(slot)

pastBoundedSlotIndex := latestCommitmentSlot + apiForSlot.ProtocolParameters().MaxCommittableAge()
pastBoundedEpochIndex := apiForSlot.TimeProvider().EpochFromSlot(pastBoundedSlotIndex)
pastBoundedSlot := latestCommitmentSlot + apiForSlot.ProtocolParameters().MaxCommittableAge()
pastBoundedEpoch := apiForSlot.TimeProvider().EpochFromSlot(pastBoundedSlot)

registrationSlot := w.registrationSlot(slot)

if pastBoundedSlotIndex <= registrationSlot {
return pastBoundedEpochIndex + 1
if pastBoundedSlot <= registrationSlot {
return pastBoundedEpoch + 1
}

return pastBoundedEpochIndex + 2
return pastBoundedEpoch + 2
}

func (w *Wallet) DelegationEndFromSlot(slot, latestCommitmentSlot iotago.SlotIndex) iotago.EpochIndex {
apiForSlot := w.Client.APIForSlot(slot)

futureBoundedSlotIndex := latestCommitmentSlot + apiForSlot.ProtocolParameters().MinCommittableAge()
futureBoundedEpochIndex := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex)
futureBoundedSlot := latestCommitmentSlot + apiForSlot.ProtocolParameters().MinCommittableAge()
futureBoundedEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlot)

registrationSlot := w.registrationSlot(slot)

if futureBoundedSlotIndex <= registrationSlot {
return futureBoundedEpochIndex
if futureBoundedSlot <= registrationSlot {
return futureBoundedEpoch
}

return futureBoundedEpochIndex + 1
return futureBoundedEpoch + 1
}

// Returns the registration slot in the epoch X corresponding to the given slot.
Expand All @@ -185,15 +195,15 @@ func (w *Wallet) DelayedClaimingTransition(transactionName string, input *Output
if len(optDelegationEndEpoch) == 0 {
api := w.Client.LatestAPI()
latestCommitmentSlot := w.GetNewBlockIssuanceResponse().LatestCommitment.Slot
futureBoundedSlotIndex := latestCommitmentSlot + api.ProtocolParameters().MinCommittableAge()
futureBoundedEpochIndex := api.TimeProvider().EpochFromSlot(futureBoundedSlotIndex)
futureBoundedSlot := latestCommitmentSlot + api.ProtocolParameters().MinCommittableAge()
futureBoundedEpoch := api.TimeProvider().EpochFromSlot(futureBoundedSlot)

registrationSlot := api.TimeProvider().EpochEnd(api.TimeProvider().EpochFromSlot(w.CurrentSlot())) - api.ProtocolParameters().EpochNearingThreshold()

if futureBoundedSlotIndex <= registrationSlot {
delegationEndEpoch = futureBoundedEpochIndex
if futureBoundedSlot <= registrationSlot {
delegationEndEpoch = futureBoundedEpoch
} else {
delegationEndEpoch = futureBoundedEpochIndex + 1
delegationEndEpoch = futureBoundedEpoch + 1
}
} else {
delegationEndEpoch = optDelegationEndEpoch[0]
Expand Down Expand Up @@ -394,7 +404,7 @@ func (w *Wallet) CreateImplicitAccountAndBasicOutputFromInput(transactionName st
return signedTransaction
}

func (w *Wallet) TransitionImplicitAccountToAccountOutput(transactionName string, inputs []*OutputData, opts ...options.Option[builder.AccountOutputBuilder]) *iotago.SignedTransaction {
func (w *Wallet) TransitionImplicitAccountToAccountOutputWithBlockIssuance(transactionName string, inputs []*OutputData, blockIssuance *api.IssuanceBlockHeaderResponse, opts ...options.Option[builder.AccountOutputBuilder]) *iotago.SignedTransaction {
var implicitAccountOutput *OutputData
var baseTokenAmount iotago.BaseToken
for _, input := range inputs {
Expand Down Expand Up @@ -426,7 +436,7 @@ func (w *Wallet) TransitionImplicitAccountToAccountOutput(transactionName string
AccountID: implicitAccountID,
}),
WithCommitmentInput(&iotago.CommitmentInput{
CommitmentID: w.GetNewBlockIssuanceResponse().LatestCommitment.MustID(),
CommitmentID: blockIssuance.LatestCommitment.MustID(),
}),
WithInputs(inputs...),
WithOutputs(accountOutput),
Expand All @@ -437,6 +447,12 @@ func (w *Wallet) TransitionImplicitAccountToAccountOutput(transactionName string
return signedTransaction
}

func (w *Wallet) TransitionImplicitAccountToAccountOutput(transactionName string, inputs []*OutputData, opts ...options.Option[builder.AccountOutputBuilder]) *iotago.SignedTransaction {
issuance := w.GetNewBlockIssuanceResponse()

return w.TransitionImplicitAccountToAccountOutputWithBlockIssuance(transactionName, inputs, issuance, opts...)
}

func (w *Wallet) CreateFoundryAndNativeTokensFromInput(input *OutputData, mintedAmount iotago.BaseToken, maxSupply iotago.BaseToken) *iotago.SignedTransaction {
issuer := w.BlockIssuer.AccountData
currentSlot := w.Client.LatestAPI().TimeProvider().CurrentSlot()
Expand Down
2 changes: 1 addition & 1 deletion tools/docker-network/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ COMMON_CONFIG="
--profiling.bindAddress=0.0.0.0:6061
--restAPI.publicRoutes=/health,/api/routes,/api/core/v3/info,/api/core/v3/network*,/api/core/v3/blocks*,/api/core/v3/transactions*,/api/core/v3/commitments*,/api/core/v3/outputs*,/api/core/v3/accounts*,/api/core/v3/validators*,/api/core/v3/rewards*,/api/core/v3/committee*,/api/debug/v2/*,/api/indexer/v2/*,/api/mqtt/v2,/api/blockissuer/v1/*,/api/management/v1/*
--debugAPI.enabled=false
--p2p.autopeering.maxPeers=5
--p2p.autopeering.allowLocalIPs=true
"

AUTOPEERING_CONFIG="
--p2p.autopeering.bootstrapPeers=/dns/node-1-validator/tcp/15600/p2p/12D3KooWRVt4Engu27jHnF2RjfX48EqiAqJbgLfFdHNt3Vn6BtJK
--p2p.autopeering.maxPeers=3
"

# admin/admin
Expand Down
11 changes: 6 additions & 5 deletions tools/docker-network/tests/accounttransition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/iotaledger/iota-core/tools/docker-network/tests/dockertestframework"
iotago "github.com/iotaledger/iota.go/v4"
)

Expand All @@ -18,8 +19,8 @@ import (
// 3. account1 requests faucet funds then allots 1000 mana to account2.
// 4. account2 requests faucet funds then creates native tokens.
func Test_AccountTransitions(t *testing.T) {
d := NewDockerTestFramework(t,
WithProtocolParametersOptions(
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
Expand All @@ -40,15 +41,15 @@ func Test_AccountTransitions(t *testing.T) {

// create account1
fmt.Println("Creating account1")
wallet1, _ := d.CreateAccount()
wallet1, _ := d.CreateAccountFromFaucet()

// create account2
fmt.Println("Creating account2")
wallet2, _ := d.CreateAccount()
wallet2, _ := d.CreateAccountFromFaucet()

// allot 1000 mana from account1 to account2
fmt.Println("Allotting mana from account1 to account2")
d.AllotManaTo(wallet1, wallet2.BlockIssuer.AccountData, 1000)
d.RequestFaucetFundsAndAllotManaTo(wallet1, wallet2.BlockIssuer.AccountData, 1000)

// create native token
fmt.Println("Creating native token")
Expand Down
Loading

0 comments on commit ed4f829

Please sign in to comment.