Skip to content

Commit

Permalink
Merge branch 'next-version' into nested-events
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeR26 committed Jun 6, 2024
2 parents 7702d9c + abf87d1 commit 4c65e9b
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 53 deletions.
23 changes: 7 additions & 16 deletions __tests__/rpcProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
getTestAccount,
getTestProvider,
describeIfTestnet,
waitNextBlock,
devnetETHtokenAddress,
} from './config/fixtures';
import { initializeMatcher } from './config/schema';
Expand Down Expand Up @@ -119,15 +118,20 @@ describeIfRpc('RPCProvider', () => {
estimateSpy.mockRestore();
});

describeIfDevnet('Test Estimate message fee Cairo 0', () => {
// declaration of Cairo 0 contract is no more authorized in Sepolia Testnet
describe('Test Estimate message fee', () => {
let l1l2ContractCairo0Address: string;
let l1l2ContractCairo1Address: string;

beforeAll(async () => {
const { deploy } = await account.declareAndDeploy({
contract: compiledL1L2,
});
l1l2ContractCairo0Address = deploy.contract_address;
const { deploy: deploy2 } = await account.declareAndDeploy({
contract: compiledC1v2,
casm: compiledC1v2Casm,
});
l1l2ContractCairo1Address = deploy2.contract_address;
});

test('estimate message fee Cairo 0', async () => {
Expand All @@ -146,19 +150,6 @@ describeIfRpc('RPCProvider', () => {
})
);
});
});

describe('Test Estimate message fee Cairo 1', () => {
let l1l2ContractCairo1Address: string;

beforeAll(async () => {
const { deploy: deploy2 } = await account.declareAndDeploy({
contract: compiledC1v2,
casm: compiledC1v2Casm,
});
l1l2ContractCairo1Address = deploy2.contract_address;
await waitNextBlock(provider as RpcProvider, 5000); // in Sepolia Testnet, needs pending block validation before interacting
});

test('estimate message fee Cairo 1', async () => {
const L1_ADDRESS = '0x8359E4B0152ed5A731162D3c7B0D8D56edB165'; // not coded in 20 bytes
Expand Down
14 changes: 14 additions & 0 deletions __tests__/utils/ethSigner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,18 @@ describe('Ethereum signer', () => {
);
});
});
describe('Ethereum address', () => {
test('Eth address format', async () => {
const ethAddr = '0x8359E4B0152ed5A731162D3c7B0D8D56edB165'; // not a valid 20 bytes ETh address
expect(validateAndParseEthAddress(ethAddr)).toBe(
'0x008359e4b0152ed5a731162d3c7b0d8d56edb165'
);
expect(validateAndParseEthAddress(BigInt(ethAddr))).toBe(
'0x008359e4b0152ed5a731162d3c7b0d8d56edb165'
);
expect(validateAndParseEthAddress(BigInt(ethAddr).toString(10))).toBe(
'0x008359e4b0152ed5a731162d3c7b0d8d56edb165'
);
});
});
});
58 changes: 27 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"build:dts": "tsup --clean false --dts-only",
"pretest": "npm run lint && npm run ts:check",
"test": "jest -i",
"test:coverage": "jest -i --coverage",
"posttest": "npm run format -- --log-level warn",
"test:watch": "jest --watch",
"docs": "cd www && npm run start",
Expand Down Expand Up @@ -100,7 +101,7 @@
"@scure/starknet": "~1.0.0",
"abi-wan-kanabi": "^2.2.2",
"fetch-cookie": "^3.0.0",
"get-starknet-core": "^4.0.0-next.3",
"get-starknet-core": "^4.0.0-next.4",
"isomorphic-fetch": "^3.0.0",
"lossless-json": "^4.0.1",
"pako": "^2.0.4",
Expand Down
33 changes: 30 additions & 3 deletions src/types/lib/contract/abi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ENUM_EVENT, EVENT_FIELD, STRUCT_EVENT } from '../../api/rpcspec_0_6/contract';
// import type { ENUM_EVENT, EVENT_FIELD, STRUCT_EVENT } from '../../api/rpcspec_0_6/contract';

/** ABI */
export type Abi = ReadonlyArray<FunctionAbi | AbiEvent | AbiStruct | InterfaceAbi | any>;
Expand Down Expand Up @@ -63,14 +63,35 @@ export type AbiEvent = CairoEvent | LegacyEvent;
// CairoEvent is CairoEventDefinition type if we have a leaf (end of the arborescence for an event), otherwise a new node level is created. Only for Cairo 1
export type CairoEvent = CairoEventDefinition | AbiEvents;

export type CairoEventDefinition = STRUCT_EVENT & {
// export type CairoEventDefinition = STRUCT_EVENT & {
// name: string;
// type: 'event';
// };

// export type CairoEventVariant = ENUM_EVENT & {
// name: string;
// type: string;
// };

// export type LegacyEvent = {
// name: string;
// type: 'event';
// data: EVENT_FIELD[];
// keys: EVENT_FIELD[];
// };

export type CairoEventDefinition = {
name: string;
type: 'event';
kind: 'struct';
members: Array<EVENT_FIELD>;
};

export type CairoEventVariant = ENUM_EVENT & {
export type CairoEventVariant = {
name: string;
type: string;
kind: 'enum';
variants: Array<EVENT_FIELD>;
};

export type LegacyEvent = {
Expand All @@ -79,3 +100,9 @@ export type LegacyEvent = {
data: EVENT_FIELD[];
keys: EVENT_FIELD[];
};

type EVENT_FIELD = {
name: string;
type: string;
kind: 'key' | 'data' | 'nested';
};
2 changes: 1 addition & 1 deletion src/wallet/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

/**
* Request Permission for wallet account, return addresses that are allowed by user
* @param silentMode false: request user interaction allowance. true: return only pre-allowed
* @param {boolean} [silent_mode=false] false: request user interaction allowance. true: return only pre-allowed
* @returns allowed accounts addresses
*/
export function requestAccounts(swo: StarknetWindowObject, silent_mode = false) {
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type RpcMessage, type StarknetWindowObject } from 'starknet-types-07';
import { type RpcMessage, type StarknetWindowObject } from 'get-starknet-core';

// ---- TT Request Handler
export type RpcCall = Omit<RpcMessage, 'result'>;
Expand Down
6 changes: 6 additions & 0 deletions www/docs/guides/connect_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ const myEthAccountAddressInStarknet =
const myEthSigner = new EthSigner(myEthPrivateKey);
const myEthAccount = new Account(provider, myEthAccountAddressInStarknet, myEthSigner);
```

And if you need a random Ethereum private key:

```typescript
const myPrivateKey = eth.ethRandomPrivateKey();
```

0 comments on commit 4c65e9b

Please sign in to comment.