Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit fed028a

Browse files
committed
Fix irrelevant checks on Native Token creation
1 parent c2f3774 commit fed028a

File tree

4 files changed

+15
-53
lines changed

4 files changed

+15
-53
lines changed

Diff for: pkg/tests/combined_account_transition_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func createNativetoken(ts *testsuite.TestSuite) {
252252
node1 := ts.Node("node1")
253253
node2 := ts.Node("node2")
254254

255-
tx := wallet.CreateNativeTokenFromInput("TX7", "TX5:0", "TX4:0", 50_000, 100_000)
255+
tx := wallet.CreateNativeTokenFromInput("TX7", "TX5:0", "TX4:0", 5_000_000, 10_000_000_000)
256256
ts.IssueBasicBlockWithOptions("block6", wallet, tx)
257257

258258
ts.AssertTransactionsExist(wallet.Transactions("TX7"), true, node1)

Diff for: pkg/testsuite/mock/wallet_transactions.go

+6-24
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/iotaledger/hive.go/lo"
1111
"github.com/iotaledger/hive.go/runtime/options"
1212
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger"
13-
"github.com/iotaledger/iota-core/pkg/testsuite/depositcalculator"
1413
iotago "github.com/iotaledger/iota.go/v4"
1514
"github.com/iotaledger/iota.go/v4/builder"
1615
"github.com/iotaledger/iota.go/v4/tpkg"
@@ -668,18 +667,13 @@ func (w *Wallet) CreateNFTFromInput(transactionName string, inputName string, op
668667

669668
//nolint:forcetypeassert
670669
func (w *Wallet) CreateNativeTokenFromInput(transactionName string, inputName string, accountOutputName string, mintedAmount iotago.BaseToken, maxSupply iotago.BaseToken) *iotago.SignedTransaction {
670+
if mintedAmount > maxSupply {
671+
panic("minted amount cannot be greater than max supply")
672+
}
673+
671674
input := w.Output(inputName)
672675
accountOutput := w.AccountOutput(accountOutputName)
673676

674-
minMintedAmount := lo.PanicOnErr(depositcalculator.MinDeposit(w.Node.Protocol.CommittedAPI().ProtocolParameters(), iotago.OutputFoundry, depositcalculator.WithHasNativeToken()))
675-
mintedAmount = lo.Max(minMintedAmount, mintedAmount)
676-
maxSupply = lo.Max(maxSupply, mintedAmount)
677-
678-
if mintedAmount > input.BaseTokenAmount() {
679-
panic(fmt.Sprintf("input %s does not have enough funds to mint native token", inputName))
680-
}
681-
remainderAmount := input.BaseTokenAmount() - mintedAmount
682-
683677
// transition account output, increase foundry counter by 1, the amount of account stays the same
684678
accID := accountOutput.Output().(*iotago.AccountOutput).AccountID
685679
accAddr := accID.ToAddress().(*iotago.AccountAddress)
@@ -694,28 +688,16 @@ func (w *Wallet) CreateNativeTokenFromInput(transactionName string, inputName st
694688
MeltedTokens: big.NewInt(0),
695689
}
696690

697-
foundryOutput := builder.NewFoundryOutputBuilder(accAddr, mintedAmount, accTransitionOutput.FoundryCounter, tokenScheme).
691+
foundryOutput := builder.NewFoundryOutputBuilder(accAddr, input.BaseTokenAmount(), accTransitionOutput.FoundryCounter, tokenScheme).
698692
NativeToken(&iotago.NativeTokenFeature{
699693
ID: foundryID,
700694
Amount: big.NewInt(int64(mintedAmount)),
701695
}).MustBuild()
702696

703-
outputStates := iotago.Outputs[iotago.Output]{accTransitionOutput, foundryOutput}
704-
// prepare remainder output if needed
705-
if remainderAmount > 0 {
706-
outputStates = append(outputStates, &iotago.BasicOutput{
707-
Amount: remainderAmount,
708-
UnlockConditions: iotago.BasicOutputUnlockConditions{
709-
&iotago.AddressUnlockCondition{Address: w.Address()},
710-
},
711-
Features: iotago.BasicOutputFeatures{},
712-
})
713-
}
714-
715697
return w.createSignedTransactionWithOptions(
716698
transactionName,
717699
WithInputs(utxoledger.Outputs{accountOutput, input}),
718-
WithOutputs(outputStates),
700+
WithOutputs(iotago.Outputs[iotago.Output]{accTransitionOutput, foundryOutput}),
719701
WithBlockIssuanceCreditInput(&iotago.BlockIssuanceCreditInput{
720702
AccountID: accID,
721703
}),

Diff for: tools/docker-network/tests/accounttransition_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ func Test_AccountTransitions(t *testing.T) {
5555

5656
// create native token
5757
fmt.Println("\nCreating native token")
58-
account2 = d.CreateNativeToken(account2, 5000, 10000)
58+
account2 = d.CreateNativeToken(account2, 5_000_000, 10_000_000_000)
5959
}

Diff for: tools/docker-network/tests/dockerframework.go

+7-27
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/iotaledger/hive.go/lo"
2323
"github.com/iotaledger/hive.go/runtime/options"
2424
"github.com/iotaledger/iota-core/pkg/protocol"
25-
"github.com/iotaledger/iota-core/pkg/testsuite/depositcalculator"
2625
"github.com/iotaledger/iota-core/pkg/testsuite/snapshotcreator"
2726
iotago "github.com/iotaledger/iota.go/v4"
2827
"github.com/iotaledger/iota.go/v4/api"
@@ -486,6 +485,8 @@ func (d *DockerTestFramework) AllotManaTo(from *Account, to *Account, manaToAllo
486485

487486
// CreateNativeToken request faucet funds then use it to create native token for the account, and returns the updated Account.
488487
func (d *DockerTestFramework) CreateNativeToken(from *Account, mintedAmount iotago.BaseToken, maxSupply iotago.BaseToken) (updatedAccount *Account) {
488+
require.GreaterOrEqual(d.Testing, maxSupply, mintedAmount)
489+
489490
// requesting faucet funds for native token creation
490491
ctx := context.TODO()
491492
fundsAddr, privateKey := d.getAddress(iotago.AddressEd25519)
@@ -495,15 +496,6 @@ func (d *DockerTestFramework) CreateNativeToken(from *Account, mintedAmount iota
495496
currentSlot := clt.LatestAPI().TimeProvider().SlotFromTime(time.Now())
496497
apiForSlot := clt.APIForSlot(currentSlot)
497498

498-
minMintedAmount, err := depositcalculator.MinDeposit(apiForSlot.ProtocolParameters(), iotago.OutputFoundry, depositcalculator.WithHasNativeToken())
499-
require.NoError(d.Testing, err)
500-
501-
mintedAmount = lo.Max(minMintedAmount, mintedAmount)
502-
require.GreaterOrEqual(d.Testing, mintedAmount, fundsUTXOOutput.BaseTokenAmount())
503-
maxSupply = lo.Max(maxSupply, mintedAmount)
504-
505-
remainderAmount := fundsUTXOOutput.BaseTokenAmount() - mintedAmount
506-
507499
// increase foundry counter
508500
accTransitionOutput := builder.NewAccountOutputBuilderFromPrevious(from.AccountOutput).
509501
FoundriesToGenerate(1).MustBuild()
@@ -517,34 +509,22 @@ func (d *DockerTestFramework) CreateNativeToken(from *Account, mintedAmount iota
517509
MeltedTokens: big.NewInt(0),
518510
}
519511

520-
foundryOutput := builder.NewFoundryOutputBuilder(from.AccountAddress, mintedAmount, accTransitionOutput.FoundryCounter, tokenScheme).
512+
foundryOutput := builder.NewFoundryOutputBuilder(from.AccountAddress, fundsUTXOOutput.BaseTokenAmount(), accTransitionOutput.FoundryCounter, tokenScheme).
521513
NativeToken(&iotago.NativeTokenFeature{
522514
ID: foundryID,
523515
Amount: big.NewInt(int64(mintedAmount)),
524516
}).MustBuild()
525517

526-
addressKeys := []iotago.AddressKeys{
527-
iotago.NewAddressKeysForEd25519Address(fundsAddr.(*iotago.Ed25519Address), privateKey),
528-
iotago.NewAddressKeysForEd25519Address(from.AccountOutput.UnlockConditionSet().Address().Address.(*iotago.Ed25519Address), from.BlockIssuerKey),
529-
}
530-
531-
signedTxBuilder := builder.NewTransactionBuilder(apiForSlot)
532-
533-
// prepare remainder output if needed
534-
if remainderAmount > 0 {
535-
receiveAddr, privKey := d.getAddress(iotago.AddressEd25519)
536-
remainderOutput := builder.NewBasicOutputBuilder(receiveAddr, remainderAmount).MustBuild()
537-
addressKeys = append(addressKeys, iotago.NewAddressKeysForEd25519Address(receiveAddr.(*iotago.Ed25519Address), privKey))
538-
signedTxBuilder = signedTxBuilder.AddOutput(remainderOutput)
539-
}
518+
signer := iotago.NewInMemoryAddressSigner(iotago.NewAddressKeysForEd25519Address(fundsAddr.(*iotago.Ed25519Address), privateKey),
519+
iotago.NewAddressKeysForEd25519Address(from.AccountOutput.UnlockConditionSet().Address().Address.(*iotago.Ed25519Address), from.BlockIssuerKey))
540520

541521
issuerResp, err := clt.BlockIssuance(ctx)
542522
require.NoError(d.Testing, err)
543523

544524
congestionResp, err := clt.Congestion(ctx, from.AccountAddress, lo.PanicOnErr(issuerResp.LatestCommitment.ID()))
545525
require.NoError(d.Testing, err)
546526

547-
signedTx, err := signedTxBuilder.
527+
signedTx, err := builder.NewTransactionBuilder(apiForSlot).
548528
AddInput(&builder.TxInput{
549529
UnlockTarget: fundsAddr,
550530
InputID: fundsOutputID,
@@ -562,7 +542,7 @@ func (d *DockerTestFramework) CreateNativeToken(from *Account, mintedAmount iota
562542
AddCommitmentInput(&iotago.CommitmentInput{CommitmentID: lo.Return1(issuerResp.LatestCommitment.ID())}).
563543
WithTransactionCapabilities(iotago.TransactionCapabilitiesBitMaskWithCapabilities(iotago.WithTransactionCanDoAnything())).
564544
AllotAllMana(currentSlot, from.AccountID).
565-
Build(iotago.NewInMemoryAddressSigner(addressKeys...))
545+
Build(signer)
566546
require.NoError(d.Testing, err)
567547

568548
blkID := d.SubmitPayload(ctx, signedTx, wallet.NewEd25519Account(from.AccountID, from.BlockIssuerKey), congestionResp, issuerResp)

0 commit comments

Comments
 (0)