-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3087 from tamirms/fix-txnbuild
txnbuild: Fix bug in parsing transactions with Protocol 14 operations
- Loading branch information
Showing
9 changed files
with
144 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package txnbuild | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func roundTrip(t *testing.T, operations []Operation) { | ||
kp1 := newKeypair1() | ||
sourceAccount := NewSimpleAccount(kp1.Address(), int64(9606132444168199)) | ||
|
||
tx, err := NewTransaction( | ||
TransactionParams{ | ||
SourceAccount: &sourceAccount, | ||
Operations: operations, | ||
Timebounds: NewInfiniteTimeout(), | ||
BaseFee: MinBaseFee, | ||
}, | ||
) | ||
assert.NoError(t, err) | ||
|
||
var b64 string | ||
b64, err = tx.Base64() | ||
assert.NoError(t, err) | ||
|
||
var parsedTx *GenericTransaction | ||
parsedTx, err = TransactionFromXDR(b64) | ||
assert.NoError(t, err) | ||
var ok bool | ||
tx, ok = parsedTx.Transaction() | ||
assert.True(t, ok) | ||
|
||
for i := 0; i < len(operations); i++ { | ||
assert.Equal(t, operations[i], tx.Operations()[i]) | ||
} | ||
} | ||
|
||
func TestBeginSponsoringFutureReservesRoundTrip(t *testing.T) { | ||
beginSponsoring := &BeginSponsoringFutureReserves{ | ||
SponsoredID: newKeypair1().Address(), | ||
} | ||
|
||
roundTrip(t, []Operation{beginSponsoring}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package txnbuild | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestClaimClaimableBalanceRoundTrip(t *testing.T) { | ||
claimClaimableBalance := &ClaimClaimableBalance{ | ||
BalanceID: "00000000929b20b72e5890ab51c24f1cc46fa01c4f318d8d33367d24dd614cfdf5491072", | ||
} | ||
|
||
roundTrip(t, []Operation{claimClaimableBalance}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package txnbuild | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCreateClaimableBalanceRoundTrip(t *testing.T) { | ||
and := AndPredicate(BeforeAbsoluteTimePredicate(100), BeforeRelativeTimePredicate(10)) | ||
createNativeBalance := &CreateClaimableBalance{ | ||
Amount: "1234.0000000", | ||
Asset: NativeAsset{}, | ||
Destinations: []Claimant{ | ||
NewClaimant(newKeypair1().Address(), &UnconditionalPredicate), | ||
NewClaimant(newKeypair1().Address(), &and), | ||
}, | ||
} | ||
|
||
not := NotPredicate(UnconditionalPredicate) | ||
or := OrPredicate(BeforeAbsoluteTimePredicate(100), BeforeRelativeTimePredicate(10)) | ||
createAssetBalance := &CreateClaimableBalance{ | ||
Amount: "99.0000000", | ||
Asset: CreditAsset{ | ||
Code: "COP", | ||
Issuer: "GB56OJGSA6VHEUFZDX6AL2YDVG2TS5JDZYQJHDYHBDH7PCD5NIQKLSDO", | ||
}, | ||
Destinations: []Claimant{ | ||
NewClaimant(newKeypair1().Address(), ¬), | ||
NewClaimant(newKeypair1().Address(), &or), | ||
}, | ||
} | ||
|
||
roundTrip(t, []Operation{createNativeBalance, createAssetBalance}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package txnbuild | ||
|
||
import "testing" | ||
|
||
func TestEndSponsoringFutureReservesRoundTrip(t *testing.T) { | ||
roundTrip(t, []Operation{&EndSponsoringFutureReserves{}}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters