@@ -22,6 +22,7 @@ import (
22
22
"github.com/iotaledger/hive.go/lo"
23
23
"github.com/iotaledger/hive.go/runtime/options"
24
24
"github.com/iotaledger/iota-core/pkg/protocol"
25
+ "github.com/iotaledger/iota-core/pkg/testsuite/depositcalculator"
25
26
"github.com/iotaledger/iota-core/pkg/testsuite/snapshotcreator"
26
27
iotago "github.com/iotaledger/iota.go/v4"
27
28
"github.com/iotaledger/iota.go/v4/api"
@@ -484,28 +485,35 @@ func (d *DockerTestFramework) AllotManaTo(from *Account, to *Account, manaToAllo
484
485
}
485
486
486
487
// CreateNativeToken request faucet funds then use it to create native token for the account, and returns the updated Account.
487
- func (d * DockerTestFramework ) CreateNativeToken (from * Account ) (updatedAccount * Account ) {
488
+ func (d * DockerTestFramework ) CreateNativeToken (from * Account , mintedAmount iotago. BaseToken , maxSupply iotago. BaseToken ) (updatedAccount * Account ) {
488
489
// requesting faucet funds for native token creation
489
490
ctx := context .TODO ()
490
491
fundsAddr , privateKey := d .getAddress (iotago .AddressEd25519 )
491
492
fundsOutputID , fundsUTXOOutput := d .RequestFaucetFunds (ctx , fundsAddr )
492
493
493
- mintedAmount := fundsUTXOOutput .BaseTokenAmount ()
494
-
495
494
clt := d .Node ("V1" ).Client
496
495
currentSlot := clt .LatestAPI ().TimeProvider ().SlotFromTime (time .Now ())
497
496
apiForSlot := clt .APIForSlot (currentSlot )
498
497
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
+
499
507
// increase foundry counter
500
508
accTransitionOutput := builder .NewAccountOutputBuilderFromPrevious (from .AccountOutput ).
501
509
FoundriesToGenerate (1 ).MustBuild ()
502
510
503
- // build foundry output, consume all amount from the UTXO output
511
+ // build foundry output
504
512
foundryID , err := iotago .FoundryIDFromAddressAndSerialNumberAndTokenScheme (from .AccountAddress , accTransitionOutput .FoundryCounter , iotago .TokenSchemeSimple )
505
513
require .NoError (d .Testing , err )
506
514
tokenScheme := & iotago.SimpleTokenScheme {
507
515
MintedTokens : big .NewInt (int64 (mintedAmount )),
508
- MaximumSupply : big .NewInt (int64 (mintedAmount )),
516
+ MaximumSupply : big .NewInt (int64 (maxSupply )),
509
517
MeltedTokens : big .NewInt (0 ),
510
518
}
511
519
@@ -515,17 +523,28 @@ func (d *DockerTestFramework) CreateNativeToken(from *Account) (updatedAccount *
515
523
Amount : big .NewInt (int64 (mintedAmount )),
516
524
}).MustBuild ()
517
525
518
- // prepare transaction
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
+ }
540
+
519
541
issuerResp , err := clt .BlockIssuance (ctx )
520
542
require .NoError (d .Testing , err )
521
543
522
544
congestionResp , err := clt .Congestion (ctx , from .AccountAddress , lo .PanicOnErr (issuerResp .LatestCommitment .ID ()))
523
545
require .NoError (d .Testing , err )
524
546
525
- signer := iotago .NewInMemoryAddressSigner (iotago .NewAddressKeysForEd25519Address (fundsAddr .(* iotago.Ed25519Address ), privateKey ),
526
- iotago .NewAddressKeysForEd25519Address (from .AccountOutput .UnlockConditionSet ().Address ().Address .(* iotago.Ed25519Address ), from .BlockIssuerKey ))
527
-
528
- signedTx , err := builder .NewTransactionBuilder (apiForSlot ).
547
+ signedTx , err := signedTxBuilder .
529
548
AddInput (& builder.TxInput {
530
549
UnlockTarget : fundsAddr ,
531
550
InputID : fundsOutputID ,
@@ -543,7 +562,7 @@ func (d *DockerTestFramework) CreateNativeToken(from *Account) (updatedAccount *
543
562
AddCommitmentInput (& iotago.CommitmentInput {CommitmentID : lo .Return1 (issuerResp .LatestCommitment .ID ())}).
544
563
WithTransactionCapabilities (iotago .TransactionCapabilitiesBitMaskWithCapabilities (iotago .WithTransactionCanDoAnything ())).
545
564
AllotAllMana (currentSlot , from .AccountID ).
546
- Build (signer )
565
+ Build (iotago . NewInMemoryAddressSigner ( addressKeys ... ) )
547
566
require .NoError (d .Testing , err )
548
567
549
568
blkID := d .SubmitPayload (ctx , signedTx , wallet .NewEd25519Account (from .AccountID , from .BlockIssuerKey ), congestionResp , issuerResp )
0 commit comments