-
Notifications
You must be signed in to change notification settings - Fork 503
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
txnbuild: add AddSignatureDecorated to FeeBumpTransaction #4174
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1638,6 +1638,51 @@ func TestAddSignatureDecorated(t *testing.T) { | |
} | ||
} | ||
|
||
func TestFeeBumpTransaction_AddSignatureDecorated(t *testing.T) { | ||
kp0 := newKeypair0() | ||
kp1 := newKeypair1() | ||
|
||
tx, err := NewTransaction(TransactionParams{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this new transaction creation could go into a helper function since it seems to be used as the standard transaction across multiple tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could, but then the tests would become more coupled together. I've found it is easier to maintain tests in the long run if they are mostly independent of each other. Helper functions can be helpful, but they will also narrow the inputs to tests, or balloon into big configurable things of their own. Also this way they act as an example of the public API as much as possible. |
||
SourceAccount: &SimpleAccount{kp0.Address(), int64(9605939170639897)}, | ||
Operations: []Operation{&CreateAccount{ | ||
Destination: "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z", | ||
Amount: "10", | ||
SourceAccount: kp1.Address(), | ||
}}, | ||
BaseFee: MinBaseFee, | ||
Timebounds: NewInfiniteTimeout(), | ||
}) | ||
require.NoError(t, err) | ||
tx, err = tx.Sign(network.TestNetworkPassphrase, kp0, kp1) | ||
require.NoError(t, err) | ||
|
||
fbtx, err := NewFeeBumpTransaction(FeeBumpTransactionParams{ | ||
Inner: tx, | ||
FeeAccount: kp0.Address(), | ||
BaseFee: MinBaseFee, | ||
}) | ||
require.NoError(t, err) | ||
require.Len(t, fbtx.Signatures(), 0) | ||
|
||
fbtxHash, err := fbtx.Hash(network.TestNetworkPassphrase) | ||
require.NoError(t, err) | ||
|
||
sig, err := kp0.SignDecorated(fbtxHash[:]) | ||
require.NoError(t, err) | ||
fbtxWithSig, err := fbtx.AddSignatureDecorated(sig) | ||
require.NoError(t, err) | ||
require.Len(t, fbtx.Signatures(), 0) | ||
require.Len(t, fbtxWithSig.Signatures(), 1) | ||
|
||
sig, err = kp1.SignDecorated(fbtxHash[:]) | ||
require.NoError(t, err) | ||
fbtxWithTwoSigs, err := fbtxWithSig.AddSignatureDecorated(sig) | ||
require.NoError(t, err) | ||
require.Len(t, fbtx.Signatures(), 0) | ||
require.Len(t, fbtxWithSig.Signatures(), 1) | ||
require.Len(t, fbtxWithTwoSigs.Signatures(), 2) | ||
} | ||
|
||
func TestAddSignatureBase64(t *testing.T) { | ||
kp0 := newKeypair0() | ||
kp1 := newKeypair1() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally prefer wrapping errors so the context isn't lost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I often do that too, but there is a series of add signature functions of which this is just one variation that was missing on this type and this is how they all work, with the errors being well defined within the concat functions.