diff --git a/src/server.ts b/src/server.ts index 6884f90ad..e0e60ce47 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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"; @@ -701,7 +707,13 @@ export class Server { * requires a memo, the promise will throw {@link AccountRequiresMemoError}. * @throws {AccountRequiresMemoError} */ - public async checkMemoRequired(transaction: Transaction): Promise { + public async checkMemoRequired( + transaction: Transaction | FeeBumpTransaction, + ): Promise { + if (transaction instanceof FeeBumpTransaction) { + transaction = transaction.innerTransaction; + } + if (transaction.memo.type !== "none") { return; } diff --git a/test/unit/server_check_memo_required_test.js b/test/unit/server_check_memo_required_test.js index 7bc500995..73e197c63 100644 --- a/test/unit/server_check_memo_required_test.js +++ b/test/unit/server_check_memo_required_test.js @@ -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(); @@ -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 = {}) { @@ -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, {});