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 SEP0029 support for FeeBumpTransaction. #535

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import BigNumber from "bignumber.js";
import isEmpty from "lodash/isEmpty";
import merge from "lodash/merge";
import { Asset, StrKey, Transaction, xdr } from "stellar-base";
import {
Asset,
FeeBumpTransaction,
StrKey,
Transaction,
xdr,
} from "stellar-base";
import URI from "urijs";

import { CallBuilder } from "./call_builder";
Expand Down Expand Up @@ -701,7 +707,13 @@ export class Server {
* requires a memo, the promise will throw {@link AccountRequiresMemoError}.
* @throws {AccountRequiresMemoError}
*/
public async checkMemoRequired(transaction: Transaction): Promise<void> {
public async checkMemoRequired(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @abuiles, if the operation destination is an M.. address, can Horizon load it correctly? Or should we skip this single check?

https://github.com/stellar/js-stellar-sdk/pull/535/files#diff-916156c481141bfcd08c6ae40ce10e00R742

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@overcat that's a great question, I believe we should skip the check if the destination is an M address since M addresses essentially encode a memo within them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@overcat good catch!

transaction: Transaction | FeeBumpTransaction,
): Promise<void> {
if (transaction instanceof FeeBumpTransaction) {
transaction = transaction.innerTransaction;
}

if (transaction.memo.type !== "none") {
return;
}
Expand Down
34 changes: 32 additions & 2 deletions test/unit/server_check_memo_required_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function buildTransaction(destination, operations = [], builderOpts = {}) {
let txBuilderOpts = {
fee: 100,
networkPassphrase: StellarSdk.Networks.TESTNET
networkPassphrase: StellarSdk.Networks.TESTNET,
v1: true
};
Object.assign(txBuilderOpts, builderOpts);
let keypair = StellarSdk.Keypair.random();
Expand All @@ -22,7 +23,16 @@ function buildTransaction(destination, operations = [], builderOpts = {}) {
.build();
transaction.sign(keypair);

return transaction;
if (builderOpts.feeBump) {
return StellarSdk.TransactionBuilder.buildFeeBumpTransaction(
keypair,
'200',
transaction,
txBuilderOpts.networkPassphrase
);
} else {
return transaction;
}
}

function buildAccount(id, data = {}) {
Expand Down Expand Up @@ -125,6 +135,26 @@ describe("server.js check-memo-required", function() {
});
});

it("fee bump - fails if memo is required", function(done) {
let accountId = "GAYHAAKPAQLMGIJYMIWPDWCGUCQ5LAWY4Q7Q3IKSP57O7GUPD3NEOSEA";
mockAccountRequest(this.axiosMock, accountId, 200, { "config.memo_required": "MQ==" });
let transaction = buildTransaction(accountId, [], {feeBump: true});

this.server
.checkMemoRequired(transaction)
.then(function() {
expect.fail("promise should have failed");
}, function(err) {
expect(err).to.be.instanceOf(StellarSdk.AccountRequiresMemoError);
expect(err.accountId).to.eq(accountId);
expect(err.operationIndex).to.eq(0);
done();
})
.catch(function(err) {
done(err);
});
});

it("returns false if account doesn't exist", function(done) {
let accountId = "GAYHAAKPAQLMGIJYMIWPDWCGUCQ5LAWY4Q7Q3IKSP57O7GUPD3NEOSEA";
mockAccountRequest(this.axiosMock, accountId, 404, {});
Expand Down