Skip to content

Commit

Permalink
Merge pull request #1067 from starknet-io/next-version
Browse files Browse the repository at this point in the history
Next version
  • Loading branch information
tabaktoni authored Apr 23, 2024
2 parents a85d48e + b038c76 commit e946a60
Show file tree
Hide file tree
Showing 73 changed files with 1,364 additions and 2,090 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# TODO - periodically check if conditional services are supported; https://github.com/actions/runner/issues/822
services:
devnet:
image: ${{ (inputs.use-devnet) && 'shardlabs/starknet-devnet-rs:0.0.3-seed0' || '' }}
image: ${{ (inputs.use-devnet) && 'shardlabs/starknet-devnet-rs:0.0.4-seed0' || '' }}
ports:
- 5050:5050

Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ For major changes that markedly transform the existing API or significantly alte
## Need help?

If you want to contribute but have any questions, concerns or doubts, feel free to ping maintainers. Ideally create a pull request with `WIP` (Work in progress) in its title and ask questions in the pull request description.

You can also ask your query on our dedicated channel for [Starknet.js](https://discord.com/channels/793094838509764618/927918707613786162) on the [Starknet Discord](https://discord.com/invite/YgsdxEx3)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Guides can be found [here](https://www.starknetjs.com/docs/guides/intro) :book:

If you consider to contribute to this project please read [CONTRIBUTING.md](https://github.com/starknet-io/starknet.js/blob/main/CONTRIBUTING.md) first.

You can also join our dedicated channel for [Starknet.js](https://discord.com/channels/793094838509764618/927918707613786162) on the [Starknet Discord](https://discord.com/invite/YgsdxEx3)

## ❤️ Special Thanks

Special thanks to all the [contributors](https://github.com/starknet-io/starknet.js/graphs/contributors), especially to:
Expand Down
7 changes: 2 additions & 5 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
compiledOpenZeppelinAccount,
compiledTestDapp,
describeIfDevnet,
describeIfDevnetSequencer,
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', () => {
describeIfDevnet('Test on 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 @@ -753,7 +750,7 @@ describe('deploy and test Wallet', () => {
});

describe('unit', () => {
describeIfDevnetSequencer('devnet sequencer', () => {
describeIfDevnet('Devnet', () => {
initializeMatcher(expect);
const provider = getTestProvider();
const account = getTestAccount(provider);
Expand Down
20 changes: 10 additions & 10 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 @@ -26,7 +26,7 @@ import {
compiledHelloSierra,
compiledHelloSierraCasm,
describeIfDevnet,
describeIfSequencerGoerli,
describeIfTestnet,
getTestAccount,
getTestProvider,
} from './config/fixtures';
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"
`;
13 changes: 5 additions & 8 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_DEVNET === 'true') {
// accelerate the tests when running locally
const originalWaitForTransaction = provider.waitForTransaction.bind(provider);
provider.waitForTransaction = (txHash: string, options: waitForTransactionOptions = {}) => {
Expand All @@ -104,18 +104,15 @@ export const getTestAccount = (provider: ProviderInterface) => {
};

export const createBlockForDevnet = async (): Promise<void> => {
if (!(process.env.IS_RPC_DEVNET === 'true')) return;
if (!(process.env.IS_DEVNET === 'true')) return;
await fetch(new URL('/create_block', process.env.TEST_RPC_URL), { method: 'POST' });
};

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 describeIfNotDevnet = describeIf(process.env.IS_DEVNET === 'false');
export const describeIfDevnet = describeIf(process.env.IS_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_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

0 comments on commit e946a60

Please sign in to comment.