Skip to content

Next version #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d35f154
refactor: getStarkName & getStarkProfile for latest version of contract
irisdv Apr 22, 2024
23ae319
Snjs enc dec doc (#1101)
PhilippeR26 Apr 25, 2024
ae5dcf9
chore: add examples to JsDoc for num.ts file (#1100)
NueloSE Apr 26, 2024
8ba8d10
Merge pull request #1093 from irisdv/ref/starknetid_address_to_domain
tabaktoni Apr 29, 2024
f77bae5
chore: Add JsDoc comments and examples for merkle.ts file (#1107)
NueloSE Apr 29, 2024
0b25aba
chore: Add JsDoc comments and examples for selector.ts file (#1106)
NueloSE Apr 29, 2024
0ab0de7
chore: add examples to JsDoc for transaction.ts file (#1105)
petersdt Apr 29, 2024
59eb01e
Revert "chore: add examples to JsDoc for transaction.ts file (#1105)"…
ivpavici Apr 29, 2024
1f3c934
chore/add JsDoc for address.ts file (#1096)
BlackStarkGoku May 2, 2024
0303b21
Revert "chore: Add JsDoc comments and examples for merkle.ts file (#1…
tabaktoni May 6, 2024
cc4b0af
Revert "chore: Add JsDoc comments and examples for selector.ts file (…
tabaktoni May 6, 2024
3a58b84
Revert "chore: add examples to JsDoc for num.ts file (#1100)"
tabaktoni May 6, 2024
933220a
chore: curent changelog
tabaktoni May 6, 2024
eceda5d
feat: add type coverage (#1120)
saimeunt May 6, 2024
f1c3b8e
fix: cannot infer ts2742 types from [email protected] (#1098)
0xknwn May 17, 2024
cfcf93b
Verify message fix (#1128)
tabaktoni May 17, 2024
57e4e17
Remove all code for Goerli testnet (#1122)
PhilippeR26 May 17, 2024
1489cf2
feat: provider.getL1MessageHash (#1123)
PhilippeR26 May 17, 2024
195186f
fix: remove [warning] from typedoc for external usage (#1095)
0xknwn May 17, 2024
242baff
docs: relocate documentation of eth randomness (#1130)
PhilippeR26 May 20, 2024
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
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
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
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
Loading