Skip to content
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

Implementing getBalances, getBalance, getAddress and canSign methods #24

Merged
merged 3 commits into from
May 23, 2024

Conversation

erdimaden
Copy link
Contributor

@erdimaden erdimaden commented May 22, 2024

What changed? Why?

I am adding the getBalances, getBalance, getAddress, and canSign methods, along with their respective test cases.

Qualified Impact

@erdimaden erdimaden force-pushed the feat/balance-and-address-changes branch 2 times, most recently from aabf433 to 41a52d9 Compare May 22, 2024 20:35
@erdimaden erdimaden force-pushed the feat/balance-and-address-changes branch from 41a52d9 to c04e25e Compare May 22, 2024 20:38
@erdimaden erdimaden changed the title Adding listBalance, getBalance, getAddress and canSign methods Implementing listBalance, getBalance, getAddress and canSign methods May 22, 2024
Coinbase.apiClients.address!.createAddress = mockReturnValue(mockAddressModel);
wallet = await Wallet.create();
});
it("should return true when the wallet initialized ", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we test when the wallet does not have a seed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alex-stone Based on my understanding, wallet = await Wallet.create(); does not provide an option to include or exclude a seed. Regardless of whether we use Wallet.create or Wallet.init, the Wallet class will always have a master wallet after creation. I added this method to ensure parity with the Ruby SDK. Please let me know if there's any specific aspect you're concerned about or if I have misunderstood your point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Synced offline: Let's add that when we add listing wallets support

@@ -171,4 +184,156 @@ describe("Wallet Class", () => {
expect(newWallet).toBeInstanceOf(Wallet);
});
});

describe(".defaultAddress", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're aiming for consistency with ruby and are using the . prefixes, we should do:

describe(".classMethod", ...

and

describe("#instanceMethod", ...

E.g.

Suggested change
describe(".defaultAddress", () => {
describe("#defaultAddress", () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'm going to update this. I will also update all test files. (tracking with PSDK-165)

@erdimaden erdimaden changed the title Implementing listBalance, getBalance, getAddress and canSign methods Implementing getBalances, getBalance, getAddress and canSign methods May 23, 2024
* @returns Whether the Wallet has a seed with which to derive keys and sign transactions.
*/
public canSign(): boolean {
return this.master.publicKey !== undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this just be this.publicKey !== undefined ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the Ruby SDK, we check with the master wallet. Additionally, we do not store the public key directly in the Wallet class. Instead, the privateKey or publicKey should be accessible through the master wallet.

Ruby implementation:
Screenshot 2024-05-23 at 10 37 37 AM

const defaultAddress = wallet.defaultAddress();
const address = wallet.getAddress(defaultAddress?.getId());
expect(address).toBeInstanceOf(Address);
expect(address?.getId()).toBe(address.getId());
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also have this just assert on the mockAddressModel.AddresId to reduce coupling on getAddress behavior.

});
});

describe(".networkId", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This and wlaletId should probably be # too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will have a PR for this changes (PSDK-165)

Coinbase.apiClients.address!.createAddress = mockReturnValue(mockAddressModel);
wallet = await Wallet.create();
});
it("should return true when the wallet initialized ", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Synced offline: Let's add that when we add listing wallets support

@erdimaden erdimaden merged commit e131bca into master May 23, 2024
6 checks passed
@erdimaden erdimaden deleted the feat/balance-and-address-changes branch June 21, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants