Skip to content

Commit

Permalink
Test Commitment Input Syntactical Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Mar 5, 2024
1 parent 91e4977 commit 08c8c30
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1260,3 +1260,99 @@ func TestTransactionIDsLexicalOrderAndUniqueness(t *testing.T) {
t.Run(tt.Name, tt.Run)
}
}

func TestCommitmentInputSyntacticalValidation(t *testing.T) {
accountWithFeatures := func(feats iotago.AccountOutputFeatures) *iotago.AccountOutput {
return &iotago.AccountOutput{
Amount: 100_000_000,
UnlockConditions: iotago.AccountOutputUnlockConditions{
&iotago.AddressUnlockCondition{
Address: tpkg.RandAccountAddress(),
},
},
ImmutableFeatures: iotago.AccountOutputImmFeatures{},
Features: feats,
}
}

tests := []*frameworks.DeSerializeTest{
// fail - BlockIssuerFeature on output side without Commitment Input
{
Name: "fail - BlockIssuerFeature on output side without Commitment Input",
Source: tpkg.RandSignedTransaction(tpkg.ZeroCostTestAPI, func(t *iotago.Transaction) {
t.Outputs = iotago.TxEssenceOutputs{
accountWithFeatures(
iotago.AccountOutputFeatures{
&iotago.BlockIssuerFeature{
ExpirySlot: 100,
BlockIssuerKeys: tpkg.RandBlockIssuerKeys(3),
},
},
),
}
// Make sure there are no Context Inputs added by the rand function for this test.
t.TransactionEssence.ContextInputs = nil
}),
Target: &iotago.SignedTransaction{},
SeriErr: iotago.ErrBlockIssuerCommitmentInputMissing,
DeSeriErr: iotago.ErrBlockIssuerCommitmentInputMissing,
},
// fail - StakingFeature on output side without Commitment Input
{
Name: "fail - StakingFeature on output side without Commitment Input",
Source: tpkg.RandSignedTransaction(tpkg.ZeroCostTestAPI, func(t *iotago.Transaction) {
t.Outputs = iotago.TxEssenceOutputs{
accountWithFeatures(
iotago.AccountOutputFeatures{
&iotago.BlockIssuerFeature{
ExpirySlot: 100,
BlockIssuerKeys: tpkg.RandBlockIssuerKeys(3),
},
&iotago.StakingFeature{
StakedAmount: 1,
FixedCost: 1,
StartEpoch: 10,
EndEpoch: 12,
},
},
),
}
// Make sure there are no Context Inputs added by the rand function for this test.
t.TransactionEssence.ContextInputs = nil
}),
Target: &iotago.SignedTransaction{},
SeriErr: iotago.ErrStakingCommitmentInputMissing,
DeSeriErr: iotago.ErrStakingCommitmentInputMissing,
},
// fail - Delegation Output on output side without Commitment Input
{
Name: "fail - Delegation Output on output side without Commitment Input",
Source: tpkg.RandSignedTransaction(tpkg.ZeroCostTestAPI, func(t *iotago.Transaction) {
t.Outputs = iotago.TxEssenceOutputs{
&iotago.DelegationOutput{
Amount: 10,
DelegatedAmount: 10,
DelegationID: tpkg.RandDelegationID(),
ValidatorAddress: tpkg.RandAccountAddress(),
StartEpoch: 10,
EndEpoch: 12,
UnlockConditions: iotago.DelegationOutputUnlockConditions{
&iotago.AddressUnlockCondition{
Address: tpkg.RandEd25519Address(),
},
},
},
}
// Make sure there are no Context Inputs added by the rand function for this test.
t.TransactionEssence.ContextInputs = nil
}),
Target: &iotago.SignedTransaction{},
SeriErr: iotago.ErrDelegationCommitmentInputMissing,
DeSeriErr: iotago.ErrDelegationCommitmentInputMissing,
},
}

for _, tt := range tests {
t.Run(tt.Name, tt.Run)
}
}

0 comments on commit 08c8c30

Please sign in to comment.