Skip to content

Commit

Permalink
Add more tests to transaction builder
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed Mar 20, 2024
1 parent 6304dd5 commit 47e48b1
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions builder/transaction_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ func TestTransactionBuilder(t *testing.T) {
}
}(),

// ok - Implicit account creation address with basic input
func() *test {
inputUTXO1 := &iotago.UTXOInput{TransactionID: tpkg.Rand36ByteArray(), TransactionOutputIndex: 0}
basicInputID := &iotago.UTXOInput{TransactionID: tpkg.Rand36ByteArray(), TransactionOutputIndex: 1}
basicOutput := &iotago.BasicOutput{
Amount: 1000,
UnlockConditions: iotago.BasicOutputUnlockConditions{&iotago.AddressUnlockCondition{Address: inputAddrEd25519}},
}

input := tpkg.RandOutputOnAddress(iotago.OutputBasic, inputAddrImplicitAccountCreation)
bdl := builder.NewTransactionBuilder(tpkg.ZeroCostTestAPI, signer).
AddInput(&builder.TxInput{UnlockTarget: inputAddrImplicitAccountCreation, InputID: inputUTXO1.OutputID(), Input: input}).
AddInput(&builder.TxInput{UnlockTarget: inputAddrEd25519, InputID: basicInputID.OutputID(), Input: basicOutput}).
AddOutput(output)

return &test{
name: "ok - Implicit account creation address with basic input",
builder: bdl,
}
}(),

// ok - mix basic+chain outputs
func() *test {
var (
Expand Down Expand Up @@ -142,6 +163,67 @@ func TestTransactionBuilder(t *testing.T) {
}
}(),

// ok - with context inputs
func() *test {
inputUTXO1 := &iotago.UTXOInput{TransactionID: tpkg.Rand36ByteArray(), TransactionOutputIndex: 0}

bdl := builder.NewTransactionBuilder(tpkg.ZeroCostTestAPI, signer).
AddInput(&builder.TxInput{UnlockTarget: inputAddrEd25519, InputID: inputUTXO1.OutputID(), Input: tpkg.RandOutputOnAddress(iotago.OutputBasic, inputAddrEd25519)}).
AddOutput(output).
AddCommitmentInput(&iotago.CommitmentInput{CommitmentID: tpkg.Rand36ByteArray()}).
AddBlockIssuanceCreditInput(&iotago.BlockIssuanceCreditInput{AccountID: tpkg.RandAccountID()}).
AddRewardInput(&iotago.RewardInput{Index: 0}, 100)

return &test{
name: "ok - with context inputs",
builder: bdl,
}
}(),

// ok - allot all mana
func() *test {
inputUTXO1 := &iotago.UTXOInput{TransactionID: tpkg.Rand36ByteArray(), TransactionOutputIndex: 0}

basicOutput := &iotago.BasicOutput{
Amount: 1000_000_000,
UnlockConditions: iotago.BasicOutputUnlockConditions{&iotago.AddressUnlockCondition{Address: inputAddrEd25519}},
}

bdl := builder.NewTransactionBuilder(tpkg.ZeroCostTestAPI, signer).
AddInput(&builder.TxInput{UnlockTarget: inputAddrEd25519, InputID: inputUTXO1.OutputID(), Input: basicOutput}).
AddOutput(output).
AllotAllMana(inputUTXO1.CreationSlot()+6, tpkg.RandAccountID(), 20)

return &test{
name: "ok - allot all mana",
builder: bdl,
}
}(),

// ok - with mana lock condition
func() *test {
inputUTXO1 := &iotago.UTXOInput{TransactionID: tpkg.Rand36ByteArray(), TransactionOutputIndex: 0}

accountAddr := iotago.AccountAddressFromOutputID(inputUTXO1.OutputID())
basicOutput := &iotago.BasicOutput{
Amount: 1000,
UnlockConditions: iotago.BasicOutputUnlockConditions{
&iotago.AddressUnlockCondition{Address: accountAddr},
&iotago.TimelockUnlockCondition{Slot: inputUTXO1.CreationSlot()},
}}

bdl := builder.NewTransactionBuilder(tpkg.ZeroCostTestAPI, signer).
AddInput(&builder.TxInput{UnlockTarget: inputAddrImplicitAccountCreation, InputID: inputUTXO1.OutputID(), Input: tpkg.RandOutputOnAddress(iotago.OutputBasic, inputAddrImplicitAccountCreation)}).
SetCreationSlot(10).
AddOutput(basicOutput).
StoreRemainingManaInOutputAndAllotRemainingAccountBoundMana(inputUTXO1.CreationSlot(), 0)

return &test{
name: "ok - with mana lock condition",
builder: bdl,
}
}(),

// err - missing address keys (wrong address)
func() *test {
inputUTXO1 := &iotago.UTXOInput{TransactionID: tpkg.Rand36ByteArray(), TransactionOutputIndex: 0}
Expand Down

0 comments on commit 47e48b1

Please sign in to comment.