-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Adding Address Class with tests #10
Conversation
src/coinbase/address.ts
Outdated
import { AddressClient } from "./types"; | ||
|
||
/** | ||
* Class representing an Address in the Coinbase SDK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets be consistent on information in class docs across SDK's
Reference Ruby SDK - https://github.com/coinbase/coinbase-sdk-ruby/blob/eb7326c69a67bd8d4000d3169c01e3adfd40e97d/lib/coinbase/address.rb#L11
src/coinbase/address.ts
Outdated
private client: AddressClient; | ||
|
||
/** | ||
* Creates an instance of Address. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Creates an instance of Address. | |
* Initializes a new Address instance. |
To align with User
constructor
documentation
} | ||
|
||
/** | ||
* Requests faucet funds for the address. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: only supported on testnet networks
src/coinbase/address.ts
Outdated
); | ||
return new FaucetTransaction(response.data); | ||
} catch (e) { | ||
throw new Error(`Failed to request faucet funds`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add the api response code
and message
to the error thrown.
I think there is a ticket for this? Let's handle this soon so we don't have to retroactively replace the temporary thrown errors in many places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I'm going to throw AxiosError
for failed HTTP request.
c5da5d2
to
f7be1d3
Compare
f7be1d3
to
19563da
Compare
e32db61
to
d52fc66
Compare
54b009a
to
4cc5c7b
Compare
src/coinbase/tests/address_test.ts
Outdated
it("should request faucet funds and return a FaucetTransaction", async () => { | ||
axiosMock.onPost().reply(200, { | ||
transaction_hash: "mocked_transaction_hash", | ||
}); | ||
const address = new Address(VALID_ADDRESS_MODEL, client); | ||
const faucetTransaction = await address.faucet(); | ||
expect(faucetTransaction).toBeInstanceOf(FaucetTransaction); | ||
expect(faucetTransaction.getTransactionHash()).toBe("mocked_transaction_hash"); | ||
}); | ||
|
||
it("should request faucet funds and throw an InternalError if the request does not return a transaction hash", async () => { | ||
axiosMock.onPost().reply(200, {}); | ||
const address = new Address(VALID_ADDRESS_MODEL, client); | ||
await expect(address.faucet()).rejects.toThrow("Failed to complete faucet request"); | ||
}); | ||
|
||
it("should throw an AxiosError if faucet request fails", async () => { | ||
axiosMock.onPost().reply(400); | ||
const address = new Address(VALID_ADDRESS_MODEL, client); | ||
await expect(address.faucet()).rejects.toThrow("Request failed with status code 400"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets group these in a describe
for the method. There also is a few things missing for Ruby SDK parity in these tests.
- Faucet limit reached failure case
let(:tx_hash) { '0xdeadbeef' }
- value for transaction hash response is different
src/coinbase/tests/address_test.ts
Outdated
expect(address.getPublicKey()).toBe(newEthAddress.publicKey); | ||
expect(address.getNetworkId()).toBe(VALID_ADDRESS_MODEL.network_id); | ||
expect(address.getWalletId()).toBe(VALID_ADDRESS_MODEL.wallet_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate describe block tests for the getter methods?
src/coinbase/tests/address_test.ts
Outdated
|
||
it("should request faucet funds and throw an InternalError if the request does not return a transaction hash", async () => { | ||
axiosMock.onPost().reply(200, {}); | ||
const address = new Address(VALID_ADDRESS_MODEL, client); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these can be moved to beforeEach
block
bbef36f
to
f01cf6a
Compare
…reateAxiosMock and registerAxiosInterceptors functions - Updating Address and Coinbase class test cases
f01cf6a
to
7cd9c7d
Compare
What changed? Why?
Qualified Impact