Skip to content
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
2 changes: 1 addition & 1 deletion modules/sdk-core/src/bitgo/trading/tradingAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class TradingAccount implements ITradingAccount {
}

// we do not parse the payload here, we instead sends the payload as a stringified JSON to be signed, just like how we process it locally
const url = this.wallet.url('/tx/sign');
const url = this.bitgo.coin('ofc').url('/wallet/' + this.wallet.id() + '/tx/sign');
const payload = typeof params.payload !== 'string' ? JSON.stringify(params.payload) : params.payload;
const { signature } = await this.wallet.bitgo.post(url).send({ payload }).result();

Expand Down
11 changes: 9 additions & 2 deletions modules/sdk-core/test/unit/bitgo/trading/tradingAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ describe('TradingAccount', function () {

mockBitGo = {
post: sinon.stub().returns({ send: sendStub }),
coin: sinon.stub().callsFake((coin: string) => ({
url: sinon.stub().callsFake((url: string) => `https://app.bitgo-staging.com/api/v2/${coin}${url}`),
})),
decrypt: sinon
.stub()
.callsFake(({ input, password }) =>
Expand All @@ -48,7 +51,6 @@ describe('TradingAccount', function () {
mockWallet = {
id: sinon.stub().returns('test-wallet-id'),
keyIds: sinon.stub().returns(['user-key-id', 'bitgo-key-id']),
url: sinon.stub().returns('https://example.com/wallet/test-wallet-id/tx/sign'),
toJSON: sinon.stub().returns({
id: 'test-wallet-id',
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
Expand All @@ -73,12 +75,17 @@ describe('TradingAccount', function () {
});

describe('signPayload', function () {
it('should call the right url', async function () {
const expectedUrl = `https://app.bitgo-staging.com/api/v2/ofc/wallet/test-wallet-id/tx/sign`;
await tradingAccount.signPayload({ payload });
mockBitGo.post.calledWith(expectedUrl).should.be.true();
});

describe('without walletPassphrase or prv (BitGo remote signing)', function () {
it('should sign using the BitGo key remotely when no passphrase is provided', async function () {
const result = await tradingAccount.signPayload({ payload });

mockWallet.toJSON.calledOnce.should.be.true();
mockWallet.url.calledWith('/tx/sign').should.be.true();
mockBitGo.post.calledOnce.should.be.true();
sendStub.calledWith({ payload: JSON.stringify(payload) }).should.be.true();
result.should.equal(signature);
Expand Down
Loading