Skip to content

refactor: use sdk functions instead of fake mocks for tests#210

Merged
danielpeng1 merged 2 commits into
masterfrom
WAL-1489/replace-sdk-mocks-1
May 29, 2026
Merged

refactor: use sdk functions instead of fake mocks for tests#210
danielpeng1 merged 2 commits into
masterfrom
WAL-1489/replace-sdk-mocks-1

Conversation

@danielpeng1
Copy link
Copy Markdown
Contributor

@danielpeng1 danielpeng1 commented May 29, 2026

An initial pass of updating the tests to use the actual SDK functions instead of mocked SDK behavior.

  • Updated ecdsa.test.ts, eddsa.test.ts, generateWallet.test.ts, sendMany.test.ts
  • I created a BitGoAPITestHarness, my idea was to keep adding static methods to this class as needed as I de- mock more test files. Right now I have clearConstantsCache() so when any tests nock /api/v1/client/constants, we can get clean client constants data for each test. Should I create a utils file to move this to so we can import it instead?
  • mocha tests pass

Ticket: WAL-1489

@danielpeng1 danielpeng1 self-assigned this May 29, 2026
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 29, 2026

WAL-1489

@danielpeng1 danielpeng1 marked this pull request as ready for review May 29, 2026 13:37
@danielpeng1 danielpeng1 requested a review from a team as a code owner May 29, 2026 13:37
sinon.stub(EcdsaMPCv2Utils.prototype, 'getBitgoMpcv2PublicGpgKey').resolves(pgpKey);
const bitgoEd25519Key = await openpgpUtils.generateGPGKeyPair('ed25519');

nock(bitgoApiUrl)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

would this pr introduce any latency for ci test as we now using sdk functions?

Copy link
Copy Markdown
Contributor Author

@danielpeng1 danielpeng1 May 29, 2026

Choose a reason for hiding this comment

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

Don't think so, when running tests locally any latency was not noticeable, and looking at CI shows that the testing job for this PR took 1m 9 seconds, exactly the same time as in this older PR https://github.com/BitGo/advanced-wallets/actions/runs/25590599173/job/75127489578

Copy link
Copy Markdown
Contributor

@pranishnepal pranishnepal left a comment

Choose a reason for hiding this comment

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

will review further after current feedback is addressed!

Comment thread src/__tests__/api/master/ecdsa.test.ts Outdated
import { BitGoAPI } from '@bitgo-beta/sdk-api';
import { readKey } from 'openpgp';

class BitGoAPITestHarness extends BitGoAPI {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move this to a shared util file, then use it in tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

made a testUtils.ts

txInfo: { nP2SHInputs: 1, nSegwitInputs: 0, nOutputs: 2 },
walletId,
});
const prebuildStub = sinon
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add a nock for this also?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

was able to nock all prebuild tx stubs in sendMany

},
walletId,
});
const prebuildStub = sinon
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same question about prebuilds

@danielpeng1 danielpeng1 merged commit 9030608 into master May 29, 2026
20 checks passed
@danielpeng1 danielpeng1 deleted the WAL-1489/replace-sdk-mocks-1 branch May 29, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants