Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import {
compiledHelloSierraCasm,
compiledOpenZeppelinAccount,
compiledTestDapp,
describeIfDevnet,
describeIfDevnetSequencer,
describeIfRpcDevnet,
erc20ClassHash,
getTestAccount,
getTestProvider,
Expand Down Expand Up @@ -113,7 +112,7 @@ describe('deploy and test Wallet', () => {
// this is tested indirectly true declareAndDeploy while declaring
});

describeIfDevnetSequencer('Test on Devnet Sequencer', () => {
describeIfRpcDevnet('Test on RPC Devnet', () => {
test('deployAccount with rawArgs - test on devnet', async () => {
const priKey = stark.randomAddress();
const pubKey = ec.starkCurve.getStarkKey(priKey);
Expand Down Expand Up @@ -195,7 +194,6 @@ describe('deploy and test Wallet', () => {

describe('simulate transaction - single transaction S0.11.2', () => {
test('simulate INVOKE Cairo 0', async () => {
// INFO: Sequencer S0.11.2 support only one transaction per simulate request
const res = await account.simulateTransaction([
{
type: TransactionType.INVOKE,
Expand All @@ -206,7 +204,6 @@ describe('deploy and test Wallet', () => {
amount: uint256(10),
},
},
// This transaction will be skipped on sequencer
{
type: TransactionType.INVOKE,
contractAddress: erc20Address,
Expand Down Expand Up @@ -246,7 +243,7 @@ describe('deploy and test Wallet', () => {
expect(res).toMatchSchemaRef('SimulateTransactionResponse');
});

describeIfDevnet('declare tests only on devnet', () => {
describeIfRpcDevnet('declare tests only on devnet', () => {
test('simulate DECLARE - Cairo 0 Contract', async () => {
const res = await account.simulateTransaction([
{
Expand Down Expand Up @@ -678,7 +675,7 @@ describe('deploy and test Wallet', () => {
});
});

describeIfDevnet('declare tests only on devnet', () => {
describeIfRpcDevnet('declare tests only on devnet', () => {
test('declare, deploy & multi invoke functions', async () => {
const res = await account.estimateFeeBulk([
/* {
Expand Down Expand Up @@ -753,7 +750,7 @@ describe('deploy and test Wallet', () => {
});

describe('unit', () => {
describeIfDevnetSequencer('devnet sequencer', () => {
describeIfRpcDevnet('RPC devnet', () => {
initializeMatcher(expect);
const provider = getTestProvider();
const account = getTestAccount(provider);
Expand Down
24 changes: 12 additions & 12 deletions __tests__/cairo1.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Abi } from 'abi-wan-kanabi';
import {
Abi,
type BigNumberish,
type Calldata,
type CompiledSierra,
type DeclareDeployUDCResponse,
type RawArgsArray,
type RawArgsObject,
Account,
BigNumberish,
CallData,
Calldata,
CompiledSierra,
Contract,
ContractFactory,
DeclareDeployUDCResponse,
RawArgsArray,
RawArgsObject,
cairo,
ec,
hash,
Expand All @@ -25,8 +25,8 @@ import {
compiledComplexSierra,
compiledHelloSierra,
compiledHelloSierraCasm,
describeIfDevnet,
describeIfSequencerGoerli,
describeIfRpcDevnet,
describeIfTestnet,
getTestAccount,
getTestProvider,
} from './config/fixtures';
Expand All @@ -36,7 +36,7 @@ const { uint256, tuple, isCairo1Abi } = cairo;
const { toHex } = num;
const { starknetKeccak } = selector;

describeIfDevnet('Cairo 1 Devnet', () => {
describeIfRpcDevnet('Cairo 1 Devnet', () => {
describe('API & Contract interactions', () => {
const provider = getTestProvider();
const account = getTestAccount(provider);
Expand Down Expand Up @@ -550,8 +550,8 @@ describeIfDevnet('Cairo 1 Devnet', () => {
});
});

describeIfSequencerGoerli('Cairo1 Testnet', () => {
describe('Sequencer API - C1 Testnet C:0x00305e...', () => {
describeIfTestnet('Testnet', () => {
describe('TS validation for testnet', () => {
const provider = getTestProvider();
const account = getTestAccount(provider);
const classHash: any = '0x022332bb9c1e22ae13ae7fd9f3101eced4644533c6bfe51a25cf8dea028e5045';
Expand Down
8 changes: 8 additions & 0 deletions __tests__/config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
/* Default test config based on run `starknet-devnet --seed 0` */
export const GS_DEFAULT_TEST_PROVIDER_URL = 'http://127.0.0.1:5050/';

export const LOCAL_DEVNET_NOT_RUNNING_MESSAGE = `
Local devnet is not running. In order to properly run it you need to do the following: \n
- Go to the: https://hub.docker.com/r/shardlabs/starknet-devnet-rs/tags
- Find the latest tag and copy the "docker pull" command
- Run Docker on your machine
- Run the command: "docker pull shardlabs/starknet-devnet-rs:latest"
`;
11 changes: 4 additions & 7 deletions __tests__/config/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function getTestProvider(isProvider: boolean = true): ProviderInterface |
? new Provider({ nodeUrl: process.env.TEST_RPC_URL })
: new RpcProvider({ nodeUrl: process.env.TEST_RPC_URL });

if (process.env.IS_LOCALHOST_DEVNET === 'true') {
if (process.env.IS_RPC_DEVNET === 'true') {
// accelerate the tests when running locally
const originalWaitForTransaction = provider.waitForTransaction.bind(provider);
provider.waitForTransaction = (txHash: string, options: waitForTransactionOptions = {}) => {
Expand Down Expand Up @@ -109,13 +109,10 @@ export const createBlockForDevnet = async (): Promise<void> => {
};

const describeIf = (condition: boolean) => (condition ? describe : describe.skip);
export const describeIfSequencer = describeIf(process.env.IS_SEQUENCER === 'true');
export const describeIfRpc = describeIf(process.env.IS_RPC === 'true');
export const describeIfNotDevnet = describeIf(process.env.IS_LOCALHOST_DEVNET === 'false');
export const describeIfDevnet = describeIf(process.env.IS_LOCALHOST_DEVNET === 'true');
export const describeIfDevnetRpc = describeIf(process.env.IS_RPC_DEVNET === 'true');
export const describeIfDevnetSequencer = describeIf(process.env.IS_SEQUENCER_DEVNET === 'true');
export const describeIfSequencerGoerli = describeIf(process.env.IS_SEQUENCER_GOERLI === 'true');
export const describeIfNotRpcDevnet = describeIf(process.env.IS_RPC_DEVNET === 'false');
export const describeIfRpcDevnet = describeIf(process.env.IS_RPC_DEVNET === 'true');
export const describeIfTestnet = describeIf(process.env.IS_TESTNET === 'true');

export const erc20ClassHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';
export const wrongClassHash = '0x000000000000000000000000000000000000000000000000000000000000000';
64 changes: 64 additions & 0 deletions __tests__/config/helpers/accountResolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* eslint-disable no-console */
import { GS_DEFAULT_TEST_PROVIDER_URL } from '../constants';

class AccountResolver {
get providedUrl() {
return process.env.TEST_PROVIDER_BASE_URL || process.env.TEST_RPC_URL;
}

get hasAllAccountEnvs() {
return process.env.TEST_ACCOUNT_ADDRESS && process.env.TEST_ACCOUNT_PRIVATE_KEY;
}

get hasPartialAccountEnvs() {
return process.env.TEST_ACCOUNT_ADDRESS || process.env.TEST_ACCOUNT_PRIVATE_KEY;
}

private async fetchAccount(url: string) {
const response = await fetch(`${url}predeployed_accounts`);
const [account] = await response.json();
const { address, private_key, initial_balance } = account;
process.env.TEST_ACCOUNT_ADDRESS = address;
process.env.TEST_ACCOUNT_PRIVATE_KEY = private_key;
process.env.INITIAL_BALANCE = initial_balance;
}

private async isAccountSet(isDevnet: boolean): Promise<boolean> {
if (this.hasAllAccountEnvs) {
return true;
}
if (this.hasPartialAccountEnvs) {
throw new Error(
'If you are providing one of you need to provide both: TEST_ACCOUNT_ADDRESS & TEST_ACCOUNT_PRIVATE_KEY'
);
}
if (isDevnet) {
// get account from devnet
try {
await this.fetchAccount(GS_DEFAULT_TEST_PROVIDER_URL);
return true;
} catch (error) {
console.error('Fetching account from devnet failed');
}
} else if (this.providedUrl) {
// try to get it from remote devnet
try {
await this.fetchAccount(this.providedUrl);
return true;
} catch (error) {
console.error(`Fetching account from provided url ${this.providedUrl} failed`);
}
}

throw new Error(
'Setting Account using all known strategies failed, provide basic test parameters'
);
}

async execute(isDevnet: boolean): Promise<void> {
const isAccountSet = await this.isAccountSet(isDevnet);
if (isAccountSet) console.log('Detected Account');
}
}

export default new AccountResolver();
73 changes: 0 additions & 73 deletions __tests__/config/helpers/localDevnetDetector.ts

This file was deleted.

Loading