Skip to content

Commit

Permalink
Merge pull request #1110 from starknet-io/next-version
Browse files Browse the repository at this point in the history
Next version
  • Loading branch information
tabaktoni authored May 21, 2024
2 parents 37526cf + 242baff commit fe24214
Show file tree
Hide file tree
Showing 50 changed files with 1,452 additions and 490 deletions.
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.vscode
.idea
coverage
coverage-ts
dist
node_modules
npm-debug.log
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Bug Fixes

- starkne types 0.7 ([#1087](https://github.com/starknet-io/starknet.js/issues/1087)) ([b038c76](https://github.com/starknet-io/starknet.js/commit/b038c76fe204746f1d1023c2ad3b46c022f6edbd))
- starknet types 0.7 ([#1087](https://github.com/starknet-io/starknet.js/issues/1087)) ([b038c76](https://github.com/starknet-io/starknet.js/commit/b038c76fe204746f1d1023c2ad3b46c022f6edbd))
- tslib ([#1068](https://github.com/starknet-io/starknet.js/issues/1068)) ([dd7dc10](https://github.com/starknet-io/starknet.js/commit/dd7dc10c57fc3cc35298c0d584a178666e9cfed1))
- **utils:** fix block identifier ([#1076](https://github.com/starknet-io/starknet.js/issues/1076)) ([0a3499d](https://github.com/starknet-io/starknet.js/commit/0a3499d49751061ceae1a4d6023b34f402376efc))

Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ _[Use GitHub interface](https://blog.sapegin.me/all/open-source-for-everyone/) f
>
> All contributions are expected to be of the highest possible quality! That means the PR is thoroughly tested and documented, and without blindly generated ChatGPT code and documentation! We will not consider nor merge PR-s that do not comply to these rules!

## Prerequisites

- If it’s your first pull request, watch [this amazing course](http://makeapullrequest.com/) by [Kent C. Dodds](https://twitter.com/kentcdodds).
Expand Down Expand Up @@ -40,13 +39,13 @@ Or run tests in watch mode:
npm test --watch
```

By default the tests are executed in your local Devnet and everything should run automatically.
By default the tests are executed in your local Devnet and everything should run automatically.

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 Expand Up @@ -104,6 +103,7 @@ For major changes that markedly transform the existing API or significantly alte
- We’re using [Prettier](https://github.com/prettier/prettier) to format code, so don’t worry much about code formatting.
- Don’t commit generated files, like minified JavaScript.
- Don’t change the version number or changelog.
- Use `npm run ts:coverage` to check the global type coverage rate and `npm run ts:coverage:report` to generate a complete report (summary displayed in the console, full HTML report available in the `coverage-ts` folder by launching `./coverage-ts/index.html` in your browser) and find files having low coverage.

## Need help?

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 @@ -5,6 +5,7 @@ import { Account, Provider, ProviderInterface, RpcProvider, json } from '../../s
import { CompiledSierra, CompiledSierraCasm, LegacyCompiledContract } 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 @@ -99,11 +100,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';
Loading

0 comments on commit fe24214

Please sign in to comment.