Skip to content

Commit

Permalink
Add 'yarn _prettier' run to CI and run it (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic authored Jul 11, 2024
1 parent d0302f9 commit 704535d
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 99 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 4 additions & 4 deletions src/webauth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);
}

Expand Down Expand Up @@ -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() }'`,
);
}

Expand Down Expand Up @@ -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}`,
);
}

Expand Down
5 changes: 4 additions & 1 deletion test/integration/client_headers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
190 changes: 96 additions & 94 deletions test/unit/server_async_transaction.test.js
Original file line number Diff line number Diff line change
@@ -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));
});
});
this.server
.submitAsyncTransaction(this.transaction, { skipMemoRequiredCheck: true })
.then(function (res) {
expect(res).to.equal(response);
done();
})
.catch((err) => done(err));
});
});

0 comments on commit 704535d

Please sign in to comment.