Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests to transaction builder #711

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions builder/transaction_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ func TestTransactionBuilder(t *testing.T) {
}
}(),

// ok - Implicit account creation address with basic input
func() *test {
inputUTXO1 := &iotago.UTXOInput{TransactionID: tpkg.Rand36ByteArray(), TransactionOutputIndex: 0}
input1 := tpkg.RandOutputOnAddress(iotago.OutputBasic, inputAddrImplicitAccountCreation)

inputUTXO2 := &iotago.UTXOInput{TransactionID: tpkg.Rand36ByteArray(), TransactionOutputIndex: 1}
input2 := &iotago.BasicOutput{
Amount: 1000,
UnlockConditions: iotago.BasicOutputUnlockConditions{&iotago.AddressUnlockCondition{Address: inputAddrEd25519}},
}

bdl := builder.NewTransactionBuilder(tpkg.ZeroCostTestAPI, signer).
AddInput(&builder.TxInput{UnlockTarget: inputAddrImplicitAccountCreation, InputID: inputUTXO1.OutputID(), Input: input1}).
AddInput(&builder.TxInput{UnlockTarget: inputAddrEd25519, InputID: inputUTXO2.OutputID(), Input: input2}).
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 +164,71 @@ 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
Loading