Skip to content

Commit

Permalink
Remove all code for Goerli testnet (#1122)
Browse files Browse the repository at this point in the history
* test: eth signer

* test: move secp256k1Point tests in a dedicated test file

* feat: helper for  transaction receipt

* simplify extends for account class

* feat: handling of cairo u512 type

* refactor: change name of variable : GetTxReceiptResponseWithoutHelper

* fix: double lines for same imports

* fix: solve an error in validate.ts initiated by pr 1007

* fix: correction of a word in guide

* docs: validateChecksumAddress

* fix: jsdoc correction

* docs: add tsdoc in utils/address.ts

* test: add extra fees

* fix: estimateFeeBulk include skipValidate in accountInvocationsFactory

* feat: add type guard to receipt response status methods

* fix: repair i128 typed data encoding and add typed data range checks

* chore: update left over StarkNet casing

* feat: bundle resolution, module, type import for walletacc

* feat: bundle resolution, module, type import for walletaccount

* chore: fix connect import

* chore: add get-starknet-core next as dependencie

* chore: import fix

* fix: estimateMessageFee - eth address format (#1040)

* fix: estimatemessagefee eth address format

* fix: implement requests

* docs: small guides cleanup (#1048)

* docs: fix nodeUrl code typo (#1046)

* docs: small guides cleanup

---------

Co-authored-by: Joel Mun <hj923@hotmail.com>

* fix(RpcProvider): allow client to provide `specVersion` in 0.7 provider

this saves an extra call on RPC for optionally-known information (like the `chainId` case).
also fixed speck -> spec typo

* fix: remove abis parameter from signer and account execute

* feat: configure u512 and Secp256k1Point for abiwan

* chore: bump dependencies

* chore: expose data gas consumed and data gas price for 0.7 rpc

* refactor: remove all code for Goerli testnet

* feat: add provider.waitForBlock

* test: bump ci tests to devnet-rs v0.0.5

* fix: solve conflict

---------

Co-authored-by: gregory <10611760+gregoryguillou@users.noreply.github.com>
Co-authored-by: Toni Tabak <tabaktoni@gmail.com>
Co-authored-by: ivpavici <ivan.pavicic@live.com>
Co-authored-by: Petar Penovic <pp@spaceshard.io>
Co-authored-by: Joel Mun <hj923@hotmail.com>
Co-authored-by: Abraham Makovetsky <avimak@gmail.com>
Co-authored-by: Haroune Mohammedi <haroune.mohammedi@quadratic-labs.com>
Co-authored-by: Dhruv Kelawala <dhruvrk2000@gmail.com>
  • Loading branch information
9 people authored May 17, 2024
1 parent cfcf93b commit 57e4e17
Show file tree
Hide file tree
Showing 23 changed files with 367 additions and 231 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.4-seed0' || '' }}
image: ${{ (inputs.use-devnet) && 'shardlabs/starknet-devnet-rs:0.0.5-seed0' || '' }}
ports:
- 5050:5050

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/manual-tests-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
name: [rpc-goerli]
name: [rpc-sepolia]

uses: ./.github/workflows/_test.yml
secrets:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
name: [rpc-goerli]
name: [rpc-sepolia]

uses: ./.github/workflows/_test.yml
secrets:
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ By default the tests are executed in your local Devnet and everything should run
If you want to use a specific RPC node, you have to set some global variables before executing the tests:

```bash
export TEST_RPC_URL=http://192.168.1.44:9545/rpc/v0.5 # example of a Pathfinder node located in your local network
export TEST_RPC_URL=https://starknet-testnet.public.blastapi.io/rpc/v0.5 # example of a public testnet node
export TEST_RPC_URL=http://192.168.1.44:9545/rpc/v0_7 # example of a Pathfinder node located in your local network
export TEST_RPC_URL=https://starknet-sepolia.public.blastapi.io/rpc/v0_7 # example of a public Sepolia testnet node
export TEST_ACCOUNT_ADDRESS=0x065A822f0000000000000000000000000c26641
export TEST_ACCOUNT_PRIVATE_KEY=0x02a80000000000000000000000001754438a
```
Expand Down
File renamed without changes.
56 changes: 21 additions & 35 deletions __tests__/account.starknetId.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,34 @@ describe('deploy and test Wallet', () => {

beforeAll(async () => {
// Deploy Starknet id contract
const idResponse = await account.declareAndDeploy(
{
contract: compiledStarknetId,
casm: compiledStarknetIdCasm,
constructorCalldata: [account.address, 0],
},
{ maxFee: 1e18 }
);
const idResponse = await account.declareAndDeploy({
contract: compiledStarknetId,
casm: compiledStarknetIdCasm,
constructorCalldata: [account.address, 0],
});
identityAddress = idResponse.deploy.contract_address;

// Deploy pricing contract
const pricingResponse = await account.declareAndDeploy(
{
contract: compiledPricing,
casm: compiledPricingCasm,
constructorCalldata: [devnetERC20Address],
},
{ maxFee: 1e18 }
);
const pricingResponse = await account.declareAndDeploy({
contract: compiledPricing,
casm: compiledPricingCasm,
constructorCalldata: [devnetERC20Address],
});
const pricingAddress = pricingResponse.deploy.contract_address;

// Deploy naming contract
const namingResponse = await account.declareAndDeploy(
{
contract: compiledNaming,
casm: compiledNamingCasm,
constructorCalldata: [identityAddress, pricingAddress, 0, account.address],
},
{ maxFee: 1e18 }
);
const namingResponse = await account.declareAndDeploy({
contract: compiledNaming,
casm: compiledNamingCasm,
constructorCalldata: [identityAddress, pricingAddress, 0, account.address],
});
namingAddress = namingResponse.deploy.contract_address;

// Deploy multicall contract
const multicallResponse = await account.declareAndDeploy(
{
contract: compiledSidMulticall,
casm: compiledSidMulticallCasm,
},
{ maxFee: 1e18 }
);
const multicallResponse = await account.declareAndDeploy({
contract: compiledSidMulticall,
casm: compiledSidMulticallCasm,
});
multicallAddress = multicallResponse.deploy.contract_address;

const { transaction_hash } = await account.execute(
Expand Down Expand Up @@ -97,8 +85,7 @@ describe('deploy and test Wallet', () => {
calldata: ['1'],
},
],
undefined,
{ maxFee: 1e18 }
undefined
);

await provider.waitForTransaction(transaction_hash);
Expand Down Expand Up @@ -130,8 +117,7 @@ describe('deploy and test Wallet', () => {
],
},
],
undefined,
{ maxFee: 1e18 }
undefined
);
await provider.waitForTransaction(transaction_hash_verifier);
});
Expand Down
56 changes: 38 additions & 18 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,12 @@ describe('deploy and test Wallet', () => {
};
const details = { maxFee: 0n };

await expect(account.execute(transaction, details)).rejects.toThrow(/zero/);
await expect(account.execute(transaction, undefined, details)).rejects.toThrow(/zero/);
await expect(account.execute(transaction, details)).rejects.toThrow(
/zero|Transaction must commit to pay a positive amount on fee./
);
await expect(account.execute(transaction, undefined, details)).rejects.toThrow(
/zero|Transaction must commit to pay a positive amount on fee./
);
});

test('execute with custom nonce', async () => {
Expand Down Expand Up @@ -415,28 +419,44 @@ describe('deploy and test Wallet', () => {
expect(toBigInt(response.number as string).toString()).toStrictEqual('57');
});

test('sign and verify EIP712 message fail', async () => {
const signature = await account.signMessage(typedDataExample);
const [r, s] = stark.formatSignature(signature);
describeIfDevnet('EIP712 verification', () => {
// currently only in Devnet-rs, because can fail in Sepolia.
// to test in all cases once PR#989 implemented.
test('sign and verify EIP712 message fail', async () => {
const signature = await account.signMessage(typedDataExample);
const [r, s] = stark.formatSignature(signature);

// change the signature to make it invalid
const r2 = toBigInt(r) + 123n;
// change the signature to make it invalid
const r2 = toBigInt(r) + 123n;

const signature2 = new Signature(toBigInt(r2.toString()), toBigInt(s));
const signature2 = new Signature(toBigInt(r2.toString()), toBigInt(s));

if (!signature2) return;
if (!signature2) return;

const verifMessageResponse: boolean = await account.verifyMessage(typedDataExample, signature2);
expect(verifMessageResponse).toBe(false);
const verifMessageResponse: boolean = await account.verifyMessage(
typedDataExample,
signature2
);
expect(verifMessageResponse).toBe(false);

const wrongAccount = new Account(provider, '0x037891', '0x026789', undefined, TEST_TX_VERSION); // non existing account
await expect(wrongAccount.verifyMessage(typedDataExample, signature2)).rejects.toThrow();
});
const wrongAccount = new Account(
provider,
'0x037891',
'0x026789',
undefined,
TEST_TX_VERSION
); // non existing account
await expect(wrongAccount.verifyMessage(typedDataExample, signature2)).rejects.toThrow();
});

test('sign and verify message', async () => {
const signature = await account.signMessage(typedDataExample);
const verifMessageResponse: boolean = await account.verifyMessage(typedDataExample, signature);
expect(verifMessageResponse).toBe(true);
test('sign and verify message', async () => {
const signature = await account.signMessage(typedDataExample);
const verifMessageResponse: boolean = await account.verifyMessage(
typedDataExample,
signature
);
expect(verifMessageResponse).toBe(true);
});
});

describe('Contract interaction with Account', () => {
Expand Down
64 changes: 0 additions & 64 deletions __tests__/cairo1.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Abi } from 'abi-wan-kanabi';
import {
type BigNumberish,
type Calldata,
Expand Down Expand Up @@ -26,7 +25,6 @@ import {
compiledHelloSierra,
compiledHelloSierraCasm,
describeIfDevnet,
describeIfTestnet,
getTestAccount,
getTestProvider,
} from './config/fixtures';
Expand Down Expand Up @@ -549,65 +547,3 @@ describeIfDevnet('Cairo 1 Devnet', () => {
});
});
});

describeIfTestnet('Testnet', () => {
describe('TS validation for testnet', () => {
const provider = getTestProvider();
const account = getTestAccount(provider);
const classHash: any = '0x022332bb9c1e22ae13ae7fd9f3101eced4644533c6bfe51a25cf8dea028e5045';
const contractAddress: any =
'0x00305ef61e86F4566b8726d8867EF252d4f37F4B6418Cad4288052738ee22A5d';
let cairo1Contract: Contract;
initializeMatcher(expect);

beforeAll(async () => {
const cairoClass = await provider.getClassByHash(classHash);
// TODO: Fix typing and responses for abi
cairo1Contract = new Contract(cairoClass.abi as Abi, contractAddress, account);
});

test('GetClassByHash', async () => {
const classResponse = await provider.getClassByHash(classHash);
expect(classResponse).toMatchSchemaRef('SierraContractClass');
});

test('GetClassAt', async () => {
const classResponse = await provider.getClassAt(contractAddress);
expect(classResponse).toMatchSchemaRef('SierraContractClass');
});

test('Cairo 1 Contract Interaction - felt252', async () => {
const result = await cairo1Contract.test_felt252(100);
expect(result).toBe(101n);
});

test('Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128', async () => {
let result = await cairo1Contract.test_u8(100n);
expect(result).toBe(107n);
result = await cairo1Contract.test_u16(100n);
expect(result).toBe(106n);
result = await cairo1Contract.test_u32(100n);
expect(result).toBe(104n);
result = await cairo1Contract.test_u64(255n);
expect(result).toBe(258n);
result = await cairo1Contract.test_u128(255n);
expect(result).toBe(257n);
});

test('Cairo 1 - uint256 struct', async () => {
const myUint256 = uint256(2n ** 256n - 2n);
const result = await cairo1Contract.test_u256(myUint256);
expect(result).toBe(2n ** 256n - 1n);
});

test('Cairo 1 - uint256 by a bignumber', async () => {
const result = await cairo1Contract.test_u256(2n ** 256n - 2n);
expect(result).toBe(2n ** 256n - 1n);
});

test('Cairo 1 Contract Interaction - bool', async () => {
const tx = await cairo1Contract.test_bool(true);
expect(tx).toBe(true);
});
});
});
2 changes: 1 addition & 1 deletion __tests__/cairo1v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ describe('Cairo 1', () => {

describe('Cairo2.6.0 Sierra1.5.0', () => {
test('declare Sierra 1.5.0', async () => {
const declare260Response = await account.declare({
const declare260Response = await account.declareIfNot({
contract: compiledC260,
casm: compiledC260Casm,
});
Expand Down
20 changes: 19 additions & 1 deletion __tests__/config/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../../src/types';
import { ETransactionVersion } from '../../src/types/api';
import { toHex } from '../../src/utils/num';
import { wait } from '../../src/utils/provider';

const readContract = (name: string): LegacyCompiledContract =>
json.parse(
Expand Down Expand Up @@ -108,11 +109,28 @@ export const createBlockForDevnet = async (): Promise<void> => {
await fetch(new URL('/create_block', process.env.TEST_RPC_URL), { method: 'POST' });
};

export async function waitNextBlock(provider: RpcProvider, delay: number) {
const initBlock = await provider.getBlockNumber();
createBlockForDevnet();
let isNewBlock: boolean = false;
while (!isNewBlock) {
// eslint-disable-next-line no-await-in-loop
const currentBlock = await provider.getBlockNumber();
if (currentBlock !== initBlock) {
isNewBlock = true;
} else {
// eslint-disable-next-line no-await-in-loop
await wait(delay);
}
}
}

const describeIf = (condition: boolean) => (condition ? describe : describe.skip);
export const describeIfRpc = describeIf(process.env.IS_RPC === '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';
export const devnetETHtokenAddress =
'0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7';
21 changes: 13 additions & 8 deletions __tests__/config/helpers/strategyResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import accountResolver from './accountResolver';
import { GS_DEFAULT_TEST_PROVIDER_URL, LOCAL_DEVNET_NOT_RUNNING_MESSAGE } from '../constants';
import { setIfNullish } from './env';
import { BaseUrl } from '../../../src/constants';
import { RpcProvider } from '../../../src';

class StrategyResolver {
private isDevnet = false;
Expand All @@ -14,7 +14,12 @@ class StrategyResolver {
}

get isTestnet() {
return process.env.TEST_RPC_URL?.includes(BaseUrl.SN_SEPOLIA);
const provider = new RpcProvider({ nodeUrl: process.env.TEST_RPC_URL });
const isTestnetSepolia = provider
.getTransactionByHash('0x28dfc05eb4f261b37ddad451ff22f1d08d4e3c24dc646af0ec69fa20e096819') // one random existing Sepolia transaction hash
.then(() => true)
.catch(() => false);
return isTestnetSepolia;
}

get hasAllAccountEnvs() {
Expand Down Expand Up @@ -47,7 +52,7 @@ class StrategyResolver {
setIfNullish('IS_DEVNET', this.isRpcDevnet);
}

resolveRpc(): void {
async resolveRpc(): Promise<void> {
const hasRpcUrl = !!process.env.TEST_RPC_URL;

this.isRpcNode = hasRpcUrl || this.isDevnet;
Expand All @@ -57,7 +62,7 @@ class StrategyResolver {
}

setIfNullish('IS_RPC', this.isRpcNode);
setIfNullish('IS_TESTNET', this.isTestnet);
setIfNullish('IS_TESTNET', await this.isTestnet);

console.log('Detected RPC');
}
Expand Down Expand Up @@ -94,10 +99,10 @@ class StrategyResolver {
}
}

private useProvidedSetup(): void {
private async useProvidedSetup(): Promise<void> {
setIfNullish('IS_DEVNET', false);
setIfNullish('IS_RPC', !!process.env.TEST_RPC_URL);
setIfNullish('IS_TESTNET', this.isTestnet);
setIfNullish('IS_TESTNET', await this.isTestnet);

this.logConfigInfo();

Expand All @@ -110,15 +115,15 @@ class StrategyResolver {
this.verifyAccountData();

if (this.hasAllAccountEnvs) {
this.useProvidedSetup();
await this.useProvidedSetup();
return;
}

// 2. Try to detect devnet setup
console.log('Basic test parameters are missing, Auto Setup Started');

await this.detectDevnet();
this.resolveRpc();
await this.resolveRpc();
await accountResolver.execute(this.isDevnet);

this.verifyAccountData(true);
Expand Down
Loading

0 comments on commit 57e4e17

Please sign in to comment.