@@ -36,7 +36,7 @@ func Test_TransitionAndDestroyAccount(t *testing.T) {
36
36
// Nil address will be replaced with the address generated from genesis seed.
37
37
Address : nil ,
38
38
// Set an amount enough to cover storage deposit and more issuer keys.
39
- Amount : mock .MinIssuerAccountAmount (ts .API .ProtocolParameters ()) * 10 ,
39
+ Amount : mock .MinIssuerAccountAmount (ts .API .ProtocolParameters ()) * 2 ,
40
40
Mana : 0 ,
41
41
// AccountID is derived from this field, so this must be set uniquely for each account.
42
42
IssuerKey : oldGenesisOutputKey ,
@@ -472,7 +472,13 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
472
472
node1 := ts .AddValidatorNode ("node1" )
473
473
node2 := ts .AddNode ("node2" )
474
474
475
- wallet1BIC := iotago .BlockIssuanceCredits (100_000_000 )
475
+ testPayload := & iotago.TaggedData {}
476
+ testPayloadWorkScore := lo .PanicOnErr (testPayload .WorkScore (ts .API .ProtocolParameters ().WorkScoreParameters ()))
477
+ minRMC := ts .API .ProtocolParameters ().CongestionControlParameters ().MinReferenceManaCost
478
+ testPayloadCost := iotago .BlockIssuanceCredits (testPayloadWorkScore ) * iotago .BlockIssuanceCredits (minRMC )
479
+
480
+ // wallet 1 starts with enough BIC to issue two test payloads
481
+ wallet1BIC := 2 * testPayloadCost
476
482
wallet2BIC := iotago .BlockIssuanceCredits (0 )
477
483
478
484
wallet1 := ts .AddGenesisWallet ("wallet 1" , node2 , testsuite .WithWalletBlockIssuanceCredits (wallet1BIC ))
@@ -505,20 +511,13 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
505
511
// MODIFY EXISTING GENESIS ACCOUNT
506
512
var block1Slot iotago.SlotIndex = 1
507
513
var latestParents []iotago.BlockID
508
- // The cost of the block that will make the account go negative.
509
- // We store it so we can allot that amount later to unlock it.
510
- block12ManaCost := iotago .Mana (0 )
511
514
// Issue one block from each of the two block-issuers - one will go negative and the other has enough BICs.
512
515
{
513
516
block1Commitment := iotago .NewEmptyCommitment (ts .API )
514
517
block1Commitment .ReferenceManaCost = ts .API .ProtocolParameters ().CongestionControlParameters ().MinReferenceManaCost
515
518
ts .SetCurrentSlot (block1Slot )
516
- block11 := ts .IssueBasicBlockWithOptions ("block1.1" , wallet1 , & iotago.TaggedData {}, mock .WithSlotCommitment (block1Commitment ))
517
- block12 := ts .IssueBasicBlockWithOptions ("block1.2" , wallet2 , & iotago.TaggedData {}, mock .WithStrongParents (block11 .ID ()), mock .WithSlotCommitment (block1Commitment ))
518
-
519
- var err error
520
- block12ManaCost , err = block12 .ProtocolBlock ().ManaCost (block1Commitment .ReferenceManaCost )
521
- require .NoError (t , err )
519
+ block11 := ts .IssueBasicBlockWithOptions ("block1.1" , wallet1 , testPayload , mock .WithSlotCommitment (block1Commitment ))
520
+ block12 := ts .IssueBasicBlockWithOptions ("block1.2" , wallet2 , testPayload , mock .WithStrongParents (block11 .ID ()), mock .WithSlotCommitment (block1Commitment ))
522
521
523
522
// Commit BIC burns and check account states.
524
523
ts .CommitUntilSlot (ts .BlockID ("block1.2" ).Slot (), block12 .ID ())
@@ -552,9 +551,9 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
552
551
{
553
552
block2Commitment := node1 .Protocol .Engines .Main .Get ().SyncManager .LatestCommitment ().Commitment ()
554
553
555
- block21 := ts .IssueBasicBlockWithOptions ("block2.1" , wallet1 , & iotago. TaggedData {} , mock .WithSlotCommitment (block2Commitment ))
554
+ block21 := ts .IssueBasicBlockWithOptions ("block2.1" , wallet1 , testPayload , mock .WithSlotCommitment (block2Commitment ))
556
555
557
- block22 := ts .IssueBasicBlockWithOptions ("block2.2" , wallet2 , & iotago. TaggedData {} , mock .WithStrongParents (ts .BlockID ("block2.1" )), mock .WithSlotCommitment (block2Commitment ))
556
+ block22 := ts .IssueBasicBlockWithOptions ("block2.2" , wallet2 , testPayload , mock .WithStrongParents (ts .BlockID ("block2.1" )), mock .WithSlotCommitment (block2Commitment ))
558
557
559
558
ts .AssertBlockFiltered ([]* blocks.Block {block22 }, iotago .ErrAccountLocked , wallet2 .Node )
560
559
@@ -586,7 +585,7 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
586
585
// Allot some mana to the locked account to unlock it.
587
586
// The locked wallet 2 is preparing and signs the transaction, but it's issued by wallet 1 whose account is not locked.
588
587
{
589
- allottedBIC := iotago . BlockIssuanceCredits ( block12ManaCost )
588
+ allottedBIC := testPayloadCost
590
589
tx1 := wallet2 .AllotManaFromInputs ("TX1" ,
591
590
iotago.Allotments {& iotago.Allotment {
592
591
AccountID : wallet2 .BlockIssuer .AccountID ,
@@ -627,7 +626,7 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) {
627
626
{
628
627
block4Commitment := node1 .Protocol .Engines .Main .Get ().SyncManager .LatestCommitment ().Commitment ()
629
628
630
- block4 := ts .IssueBasicBlockWithOptions ("block4" , wallet2 , & iotago. TaggedData {} , mock .WithStrongParents (latestParents ... ), mock .WithSlotCommitment (block4Commitment ))
629
+ block4 := ts .IssueBasicBlockWithOptions ("block4" , wallet2 , testPayload , mock .WithStrongParents (latestParents ... ), mock .WithSlotCommitment (block4Commitment ))
631
630
632
631
ts .CommitUntilSlot (ts .BlockID ("block4" ).Slot (), block4 .ID ())
633
632
@@ -768,7 +767,17 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) {
768
767
// Allot some mana to the locked account to unlock it.
769
768
// The locked wallet 1 is preparing and signs the transaction, but it's issued by wallet 2 whose account is not locked.
770
769
{
771
- allottedBIC := iotago .BlockIssuanceCredits (100_000_000 )
770
+ // create a dummy TX of the kind we want wallet 1 to issue next, so we can calculate it's cost.
771
+ dummyTx := wallet1 .TransitionAccount (
772
+ "TX3" ,
773
+ "Genesis:2" ,
774
+ mock .WithAddBlockIssuerKey (newWallet1IssuerKey ),
775
+ mock .WithBlockIssuerExpirySlot (newExpirySlot ),
776
+ )
777
+ dummyTxCost := iotago .BlockIssuanceCredits (lo .PanicOnErr (dummyTx .WorkScore (ts .API .ProtocolParameters ().WorkScoreParameters ()))) + iotago .BlockIssuanceCredits (ts .API .ProtocolParameters ().CongestionControlParameters ().MinReferenceManaCost )
778
+
779
+ // allot enough Mana to unlock the account AND cover the cost of the next transaction.
780
+ allottedBIC := dummyTxCost + 1
772
781
tx2 := wallet1 .AllotManaFromInputs ("TX2" ,
773
782
iotago.Allotments {& iotago.Allotment {
774
783
AccountID : wallet1 .BlockIssuer .AccountID ,
0 commit comments