Skip to content

Commit

Permalink
fix: fix auth test (#685)
Browse files Browse the repository at this point in the history
* rewrite

* add cs
  • Loading branch information
Cameron Manavian authored Jan 4, 2023
1 parent d0c74cd commit c280c41
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-trains-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels": patch
---

Fix test
37 changes: 21 additions & 16 deletions packages/fuel-gauge/src/auth-testing.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import type { Contract } from 'fuels';
import fs from 'fs';
import type { Contract, WalletUnlocked } from 'fuels';
import { ContractFactory, NativeAssetId, Provider, TestUtils } from 'fuels';
import path from 'path';

import { getSetupContract, getWallet } from './utils';

const setupContract = getSetupContract('auth_testing_contract');
import FactoryAbi from '../test-projects/auth_testing_contract/out/debug/auth_testing_contract-abi.json';

let contractInstance: Contract;
let wallet: WalletUnlocked;

// TODO: Fix and unskip test
describe.skip('Auth Testing', () => {
describe('Auth Testing', () => {
beforeAll(async () => {
contractInstance = await setupContract();
const provider = new Provider('http://127.0.0.1:4000/graphql');
wallet = await TestUtils.generateTestWallet(provider, [[1_000, NativeAssetId]]);

const bytecode = fs.readFileSync(
path.join(
__dirname,
'../test-projects/auth_testing_contract/out/debug/auth_testing_contract.bin'
)
);
const factory = new ContractFactory(bytecode, FactoryAbi, wallet);
contractInstance = await factory.deployContract();
});

it('can get is_caller_external', async () => {
Expand All @@ -19,8 +30,6 @@ describe.skip('Auth Testing', () => {
});

it('can check_msg_sender [with correct id]', async () => {
const wallet = getWallet();

const { value } = await contractInstance.functions
.check_msg_sender({ value: wallet.address.toB256() })
.call();
Expand All @@ -29,20 +38,16 @@ describe.skip('Auth Testing', () => {
});

it('can check_msg_sender [with correct id, using get]', async () => {
const wallet = getWallet();

expect(async () => {
await contractInstance.functions.check_msg_sender({ value: wallet.address.toB256() }).get();
}).toThrow();
}).rejects.toThrow(/Script returned non-zero result/);
});

it('can check_msg_sender [with incorrect id]', async () => {
const wallet = getWallet();

expect(async () => {
await contractInstance.functions
.check_msg_sender({ value: wallet.address.toB256().replace('x', 'y') })
.check_msg_sender({ value: wallet.address.toB256().replace('a', 'b') })
.call();
}).toThrow();
}).rejects.toThrow(/Script returned non-zero result/);
});
});
8 changes: 0 additions & 8 deletions packages/fuel-gauge/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ const createWallet = async () => {
return walletInstance;
};

export const getWallet = () => {
if (walletInstance) {
return walletInstance;
}

throw new Error('Wallet not created yet');
};

export type SetupConfig = {
contractBytecode: BytesLike;
abi: JsonAbi | Interface;
Expand Down

0 comments on commit c280c41

Please sign in to comment.