diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 89a9b81dc..2a30e3632 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,3 +40,6 @@ jobs: - name: Browser Tests run: yarn test:browser + + - name: Linter Tests + run: yarn _prettier && (git diff-index --quiet HEAD; git diff) \ No newline at end of file diff --git a/src/webauth/utils.ts b/src/webauth/utils.ts index 3e6d13c73..163f419a2 100644 --- a/src/webauth/utils.ts +++ b/src/webauth/utils.ts @@ -572,8 +572,8 @@ export function verifyChallengeTxSigners( serverKP = Keypair.fromPublicKey(serverAccountID); // can throw 'Invalid Stellar public key' } catch (err: any) { throw new Error( - "Couldn't infer keypair from the provided 'serverAccountID': " + - err.message, + `Couldn't infer keypair from the provided 'serverAccountID': ${ + err.message}`, ); } @@ -645,7 +645,7 @@ export function verifyChallengeTxSigners( // Confirm we matched a signature to the server signer. if (!serverSignatureFound) { throw new InvalidChallengeError( - "Transaction not signed by server: '" + serverKP.publicKey() + "'", + `Transaction not signed by server: '${ serverKP.publicKey() }'`, ); } @@ -751,7 +751,7 @@ export function gatherTxSigners( keypair = Keypair.fromPublicKey(signer); // This can throw a few different errors } catch (err: any) { throw new InvalidChallengeError( - "Signer is not a valid address: " + err.message, + `Signer is not a valid address: ${ err.message}`, ); } diff --git a/test/integration/client_headers_test.js b/test/integration/client_headers_test.js index bd564c1be..ccfaa045c 100644 --- a/test/integration/client_headers_test.js +++ b/test/integration/client_headers_test.js @@ -89,7 +89,10 @@ describe("integration tests: client headers", function (done) { return; } - new Horizon.Server(`http://localhost:${port}`, { headers: { "authorization": "123456789" }, allowHttp: true }) + new Horizon.Server(`http://localhost:${port}`, { + headers: { authorization: "123456789" }, + allowHttp: true, + }) .operations() .call(); }); diff --git a/test/unit/server_async_transaction.test.js b/test/unit/server_async_transaction.test.js index 0939fd0f0..fa54f8217 100644 --- a/test/unit/server_async_transaction.test.js +++ b/test/unit/server_async_transaction.test.js @@ -1,106 +1,108 @@ const { Horizon } = StellarSdk; describe("server.js async transaction submission tests", function () { - let keypair = StellarSdk.Keypair.random(); - let account = new StellarSdk.Account(keypair.publicKey(), "56199647068161"); + let keypair = StellarSdk.Keypair.random(); + let account = new StellarSdk.Account(keypair.publicKey(), "56199647068161"); - beforeEach(function () { - this.server = new Horizon.Server("https://horizon-live.stellar.org:1337"); - this.axiosMock = sinon.mock(Horizon.AxiosClient); - let transaction = new StellarSdk.TransactionBuilder(account, { - fee: StellarSdk.BASE_FEE, - networkPassphrase: StellarSdk.Networks.TESTNET, - }) - .addOperation( - StellarSdk.Operation.payment({ - destination: - "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW", - asset: StellarSdk.Asset.native(), - amount: "100.50", - }), - ) - .setTimeout(StellarSdk.TimeoutInfinite) - .build(); - transaction.sign(keypair); + beforeEach(function () { + this.server = new Horizon.Server("https://horizon-live.stellar.org:1337"); + this.axiosMock = sinon.mock(Horizon.AxiosClient); + let transaction = new StellarSdk.TransactionBuilder(account, { + fee: StellarSdk.BASE_FEE, + networkPassphrase: StellarSdk.Networks.TESTNET, + }) + .addOperation( + StellarSdk.Operation.payment({ + destination: + "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW", + asset: StellarSdk.Asset.native(), + amount: "100.50", + }), + ) + .setTimeout(StellarSdk.TimeoutInfinite) + .build(); + transaction.sign(keypair); - this.transaction = transaction; - this.blob = encodeURIComponent( - transaction.toEnvelope().toXDR().toString("base64"), - ); - }); + this.transaction = transaction; + this.blob = encodeURIComponent( + transaction.toEnvelope().toXDR().toString("base64"), + ); + }); - afterEach(function () { - this.axiosMock.verify(); - this.axiosMock.restore(); - }); + afterEach(function () { + this.axiosMock.verify(); + this.axiosMock.restore(); + }); - it("sends an async transaction", function (done) { - this.axiosMock - .expects("post") - .withArgs( - "https://horizon-live.stellar.org:1337/transactions_async", - `tx=${this.blob}`, - ) - .returns(Promise.resolve({ data: {} })); + it("sends an async transaction", function (done) { + this.axiosMock + .expects("post") + .withArgs( + "https://horizon-live.stellar.org:1337/transactions_async", + `tx=${this.blob}`, + ) + .returns(Promise.resolve({ data: {} })); - this.server - .submitAsyncTransaction(this.transaction, { skipMemoRequiredCheck: true }) - .then(() => done()) - .catch((err) => done(err)); - }); - it("sends an async transaction and gets a PENDING response", function (done) { - const response = { - tx_status: "PENDING", - hash: "db2c69a07be57eb5baefbfbb72b95c7c20d2c4d6f2a0e84e7c27dd0359055a2f", - }; + this.server + .submitAsyncTransaction(this.transaction, { skipMemoRequiredCheck: true }) + .then(() => done()) + .catch((err) => done(err)); + }); + it("sends an async transaction and gets a PENDING response", function (done) { + const response = { + tx_status: "PENDING", + hash: "db2c69a07be57eb5baefbfbb72b95c7c20d2c4d6f2a0e84e7c27dd0359055a2f", + }; - this.axiosMock - .expects("post") - .withArgs( - "https://horizon-live.stellar.org:1337/transactions_async", - `tx=${this.blob}`, - ) - .returns(Promise.resolve({ data: response })); + this.axiosMock + .expects("post") + .withArgs( + "https://horizon-live.stellar.org:1337/transactions_async", + `tx=${this.blob}`, + ) + .returns(Promise.resolve({ data: response })); - this.server - .submitAsyncTransaction(this.transaction, { skipMemoRequiredCheck: true }) - .then(function (res) { - expect(res).to.equal(response) - done(); - }) - .catch(function (err) { - done(err); - }); - }); - it("sends an async transaction and gets a Problem response", function (done) { - const response = { - type: "transaction_submission_exception", - title: "Transaction Submission Exception", - status: 500, - detail: "Received exception from stellar-core." + - "The `extras.error` field on this response contains further " + - "details. Descriptions of each code can be found at: " + - "https://developers.stellar.org/api/errors/http-status-codes/horizon-specific/transaction-submission-async/transaction_submission_exception", - extras: { - envelope_xdr: "AAAAAIUAEW3jQt3+fbT6nCASA1/8RWdp9fJ2woxqPHZPQUH/AAAAZAEH/OgAAAAgAAAAAQAAAAAAAAAAAAAAAFyIDD0AAAAAAAAAAQAAAAAAAAADAAAAAAAAAAFCQVQAAAAAAEZK09vHmzOmEMoVWYtbbZcKv3ZOoo06ckzbhyDIFKfhAAAAAAExLQAAAAABAAAAAgAAAAAAAAAAAAAAAAAAAAFPQUH/AAAAQHk3Igj+JXqggsJBFl4mrzgACqxWpx87psxu5UHnSskbwRjHZz89NycCZmJL4gN5WN7twm+wK371K9XcRNDiBwQ=", - error: "There was an exception when submitting this transaction." - } - }; + this.server + .submitAsyncTransaction(this.transaction, { skipMemoRequiredCheck: true }) + .then(function (res) { + expect(res).to.equal(response); + done(); + }) + .catch(function (err) { + done(err); + }); + }); + it("sends an async transaction and gets a Problem response", function (done) { + const response = { + type: "transaction_submission_exception", + title: "Transaction Submission Exception", + status: 500, + detail: + "Received exception from stellar-core." + + "The `extras.error` field on this response contains further " + + "details. Descriptions of each code can be found at: " + + "https://developers.stellar.org/api/errors/http-status-codes/horizon-specific/transaction-submission-async/transaction_submission_exception", + extras: { + envelope_xdr: + "AAAAAIUAEW3jQt3+fbT6nCASA1/8RWdp9fJ2woxqPHZPQUH/AAAAZAEH/OgAAAAgAAAAAQAAAAAAAAAAAAAAAFyIDD0AAAAAAAAAAQAAAAAAAAADAAAAAAAAAAFCQVQAAAAAAEZK09vHmzOmEMoVWYtbbZcKv3ZOoo06ckzbhyDIFKfhAAAAAAExLQAAAAABAAAAAgAAAAAAAAAAAAAAAAAAAAFPQUH/AAAAQHk3Igj+JXqggsJBFl4mrzgACqxWpx87psxu5UHnSskbwRjHZz89NycCZmJL4gN5WN7twm+wK371K9XcRNDiBwQ=", + error: "There was an exception when submitting this transaction.", + }, + }; - this.axiosMock - .expects("post") - .withArgs( - "https://horizon-live.stellar.org:1337/transactions_async", - `tx=${this.blob}`, - ) - .returns(Promise.resolve({ data: response })); + this.axiosMock + .expects("post") + .withArgs( + "https://horizon-live.stellar.org:1337/transactions_async", + `tx=${this.blob}`, + ) + .returns(Promise.resolve({ data: response })); - this.server - .submitAsyncTransaction(this.transaction, { skipMemoRequiredCheck: true }) - .then(function (res) { - expect(res).to.equal(response) - done(); - }) - .catch((err) => done(err)); - }); -}); \ No newline at end of file + this.server + .submitAsyncTransaction(this.transaction, { skipMemoRequiredCheck: true }) + .then(function (res) { + expect(res).to.equal(response); + done(); + }) + .catch((err) => done(err)); + }); +});