Skip to content

Commit

Permalink
Merge branch 'master' into tb/chore/remove-tags-after-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tibi77 authored Apr 18, 2023
2 parents 5999953 + d2242dc commit eec091d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-clocks-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/program": patch
---

Remove redundant falsy provider check from getBalance function within Contract class
2 changes: 2 additions & 0 deletions .changeset/wet-glasses-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
6 changes: 1 addition & 5 deletions packages/program/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { InvokeFunctions } from './types';

export default class Contract implements AbstractContract {
id!: AbstractAddress;
provider!: Provider | null;
provider!: Provider;
interface!: Interface;
account!: Account | null;
functions: InvokeFunctions = {};
Expand Down Expand Up @@ -67,10 +67,6 @@ export default class Contract implements AbstractContract {
* Get the balance for a given assset ID for this contract
*/
getBalance(assetId: BytesLike) {
if (!this.provider) {
throw new Error('Contract instance has no provider.');
}

return this.provider.getContractBalance(this.id, assetId);
}
}
16 changes: 12 additions & 4 deletions packages/wallet-manager/src/vaults/privatekey-vault.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Address } from '@fuel-ts/address';
import { Wallet } from '@fuel-ts/wallet';

import { PrivateKeyVault } from './privatekey-vault';

describe('PrivateKeyVault', () => {
const walletSpec = Wallet.generate();

it('Get wallet instance', () => {
it('should get wallet instance', () => {
const vault = new PrivateKeyVault({
secret: walletSpec.privateKey,
});
Expand All @@ -16,7 +17,7 @@ describe('PrivateKeyVault', () => {
expect(vault.getWallet(walletSpec.address).publicKey).toBe(walletSpec.publicKey);
});

it('Check if accounts are been added correctly', async () => {
it('should check if accounts have been added correctly', async () => {
const vault = new PrivateKeyVault({
secret: walletSpec.privateKey,
});
Expand All @@ -27,7 +28,7 @@ describe('PrivateKeyVault', () => {
expect(vault.getAccounts()[0].publicKey).toBe(walletSpec.publicKey);
});

it('Serialize and recreate vault state', () => {
it('should serialize and recreate vault state', () => {
const walletSpec2 = Wallet.generate();
// Initialize with privateKeys to check if it will create correctly
const vault = new PrivateKeyVault({
Expand All @@ -42,7 +43,7 @@ describe('PrivateKeyVault', () => {
expect(vaultFromState.getAccounts()[1].publicKey).toBe(walletSpec2.publicKey);
});

it('Return new account on add account', () => {
it('should return new account on add account', () => {
const vault = new PrivateKeyVault({
secret: walletSpec.privateKey,
});
Expand All @@ -52,4 +53,11 @@ describe('PrivateKeyVault', () => {

expect(account.publicKey).toBe(accounts[1].publicKey);
});

it('should throw an error when trying to add an account with an invalid private key', () => {
const vault = new PrivateKeyVault({});
const address = Address.fromRandom();

expect(() => vault.getWallet(address)).toThrow('Address not found');
});
});

0 comments on commit eec091d

Please sign in to comment.