From 9ba18409a8929a70b56eaf708c2db3d7e4cd106f Mon Sep 17 00:00:00 2001 From: Salvionied Date: Wed, 6 Dec 2023 09:51:33 +0100 Subject: [PATCH] Fix: plutus MINTS --- ApolloBuilder.go | 8 +++-- tests/txBuilding/ApolloBuilder_test.go | 43 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/ApolloBuilder.go b/ApolloBuilder.go index 67c37c8..7903cba 100644 --- a/ApolloBuilder.go +++ b/ApolloBuilder.go @@ -950,8 +950,10 @@ func (b *Apollo) Complete() (*Apollo, error) { selectedAmount = selectedAmount.Add(utxo.Output.GetValue()) } burnedValue := b.GetBurns() - selectedAmount = selectedAmount.Add(burnedValue) + mintedValue := b.getPositiveMints() + selectedAmount = selectedAmount.Add(mintedValue) requestedAmount := Value.Value{} + requestedAmount.Add(burnedValue) for _, payment := range b.payments { payment.EnsureMinUTXO(b.Context) requestedAmount = requestedAmount.Add(payment.ToValue()) @@ -1189,10 +1191,12 @@ func (b *Apollo) addChangeAndFee() (*Apollo, error) { requestedAmount = requestedAmount.Add(payment.ToValue()) } requestedAmount = requestedAmount.Add(burns) + fmt.Println("PROVIDED AMT", providedAmount) b.Fee = b.estimateFee() requestedAmount.AddLovelace(b.Fee) + fmt.Println("REQUESTED AMT", requestedAmount) change := providedAmount.Sub(requestedAmount) - + fmt.Println("CHANGE", change) if change.GetCoin() < Utils.MinLovelacePostAlonzo( TransactionOutput.SimpleTransactionOutput(b.inputAddresses[0], Value.SimpleValue(0, change.GetAssets())), b.Context, diff --git a/tests/txBuilding/ApolloBuilder_test.go b/tests/txBuilding/ApolloBuilder_test.go index 38d060b..f764207 100644 --- a/tests/txBuilding/ApolloBuilder_test.go +++ b/tests/txBuilding/ApolloBuilder_test.go @@ -521,3 +521,46 @@ func TestMintPlutus(t *testing.T) { t.Error("Tx is not correct", hex.EncodeToString(txBytes)) } } + +func TestMintPlutusWithPayment(t *testing.T) { + cc := BlockFrostChainContext.NewBlockfrostChainContext(BLOCKFROST_BASE_URL_MAINNET, int(MAINNET), "mainnetVueasSgKfYhM4PQBq0UGipAyHBpbX4oT") + decoded_addr, _ := Address.DecodeAddress("addr1qy99jvml0vafzdpy6lm6z52qrczjvs4k362gmr9v4hrrwgqk4xvegxwvtfsu5ck6s83h346nsgf6xu26dwzce9yvd8ysd2seyu") + policy := Policy.PolicyId{Value: "279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f"} + testUtxo := UTxO.UTxO{ + Input: TransactionInput.TransactionInput{ + TransactionId: []byte("d5d1f7c223dc88bb41474af23b685e0247307e94e715ef5e62f325ac94f73056"), + Index: 0, + }, + Output: TransactionOutput.SimpleTransactionOutput( + decoded_addr, + Value.SimpleValue(15000000, nil)), + } + apollob := apollo.New(&cc) + apollob, err := apollob. + AddLoadedUTxOs(testUtxo). + SetChangeAddress(decoded_addr). + MintAssetsWithRedeemer( + apollo.Unit{ + PolicyId: policy.String(), + Name: "TEST", + Quantity: int(1), + }, + Redeemer.Redeemer{}, + ).PayToAddress( + decoded_addr, + 1200000, + apollo.NewUnit( + policy.String(), + "TEST", + 1, + ), + ).Complete() + + if err != nil { + t.Error(err) + } + txBytes, err := apollob.GetTx().Bytes() + if hex.EncodeToString(txBytes) != "84a5008182584064356431663763323233646338386262343134373461663233623638356530323437333037653934653731356566356536326633323561633934663733303536000182825839010a59337f7b3a913424d7f7a151401e052642b68e948d8cacadc6372016a9999419cc5a61ca62da81e378d7538213a3715a6b858c948c69c9821a00151c56a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa1445445535401825839010a59337f7b3a913424d7f7a151401e052642b68e948d8cacadc6372016a9999419cc5a61ca62da81e378d7538213a3715a6b858c948c69c91a00cce39d021a0002e1cd09a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa14454455354010b5820aed726f17f6c88739b6d5ba2e104b948bb81f6c46e8fc0809c120021c1e6e88ba10581840000f6820000f5f6" { + t.Error("Tx is not correct", hex.EncodeToString(txBytes)) + } +}