Skip to content

Commit

Permalink
feat: rpc 0.5.0, spec refactored and rebuilt, wip testing setup refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Oct 28, 2023
1 parent f382ebd commit ecfbe19
Show file tree
Hide file tree
Showing 16 changed files with 10,328 additions and 7,052 deletions.
6 changes: 2 additions & 4 deletions __tests__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ export const compiledC1v2Casm = readContractSierraCasm('cairo/helloCairo2/compil
export const compiledC210 = readContractSierra('cairo/cairo210/cairo210.sierra');
export const compiledC210Casm = readContractSierraCasm('cairo/cairo210/cairo210');

/* Default test config based on run `starknet-devnet --seed 0` */
const DEFAULT_TEST_PROVIDER_URL = 'http://127.0.0.1:5050/';

/* User defined config or default one */
const BASE_URL = process.env.TEST_PROVIDER_BASE_URL || DEFAULT_TEST_PROVIDER_URL;
const BASE_URL =
process.env.TEST_PROVIDER_BASE_URL || process.env.GS_DEFAULT_TEST_PROVIDER_URL || '';
const RPC_URL = process.env.TEST_RPC_URL;

/* Detect user defined node or sequencer, if none default to sequencer if both default to node */
Expand Down
6 changes: 6 additions & 0 deletions __tests__/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Test Setup
* Run before each test
* ref: order of execution jestGlobalSetup.ts -> jest.setup.ts -> fixtures.ts
*/

import 'isomorphic-fetch';

/* eslint-disable no-console */
Expand Down
66 changes: 66 additions & 0 deletions __tests__/jestGlobalSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Asynchronous Global Test Setup
* Run only once
* ref: order of execution jestGlobalSetup.ts -> jest.setup.ts -> fixtures.ts
*/

/**
* Global Setup Fixtures
*/

/* Default test config based on run `starknet-devnet --seed 0` */
const GS_DEFAULT_TEST_PROVIDER_URL = 'http://127.0.0.1:5050/';

/**
* We need to detect intention of the test runner
* Does test run on local devnet?
* Does it run Sequencer or RPC tests ?
*/

const sequencerOrRpc = () => {
if (process.env.TEST_PROVIDER_BASE_URL) {
return { sequencer: true, rpc: false };
}
if (process.env.TEST_RPC_URL) {
return { sequencer: false, rpc: true };
}
// nor sequencer nor rpc provided, try with local devnet detection
return { sequencer: false, rpc: false };
};

const isAccountProvided = () => {
if (process.env.TEST_ACCOUNT_ADDRESS && process.env.TEST_ACCOUNT_PRIVATE_KEY) {
return true;
}
if (process.env.TEST_ACCOUNT_ADDRESS || process.env.TEST_ACCOUNT_PRIVATE_KEY) {
throw new Error(
'If you are providing test Account you need to provide both TEST_ACCOUNT_ADDRESS & TEST_ACCOUNT_PRIVATE_KEY'
);
}
return false;

// if not provided try to get it from BASE_URL
// if unsecesfull throw an account error
};

const defineStrategy = async () => {
// TODO: implement strategy detection
// did user provide TEST_PROVIDER_BASE_URL or TEST_RPC_URL if so we know it is RPC or Sequencer test
// if not we need to aute detect it
// did user provide TEST_ACCOUNT_ADDRESS and TEST_ACCOUNT_PRIVATE_KEY
// - if yes, use provided account
// - if only one throw error
// - if no run local devnet strategy
// did user provide TEST_PROVIDER_BASE_URL or TEST_RPC_URL
// - is local devnet running?
// - if yes, use local devnet
// get local devnet version and accounts
sequencerOrRpc();
isAccountProvided();
};

module.exports = async function (_globalConfig: any, _projectConfig: any) {
const devnetAccs = await defineStrategy();
console.log(devnetAccs);
process.env.GS_DEFAULT_TEST_PROVIDER_URL = GS_DEFAULT_TEST_PROVIDER_URL;
};
9 changes: 3 additions & 6 deletions __tests__/rpcProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ describeIfRpc('RPCProvider', () => {
expect(stateUpdate).toMatchSchemaRef('StateUpdateResponse');
});

xtest('getProtocolVersion - pathfinder not implemented', async () => {
await rpcProvider.getProtocolVersion();
});

test('getProtocolVersion - not implemented', async () => {
await expect(rpcProvider.getProtocolVersion()).rejects.toThrow();
test('getSpecVersion - pathfinder not implemented', async () => {
const spec = await rpcProvider.getSpecVersion();
console.log(spec);
});

test('getCode - not implemented', async () => {
Expand Down
Loading

0 comments on commit ecfbe19

Please sign in to comment.