Skip to content
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

Make starknet.js and abiwan fully compatible #877

Closed
haroune-mohammedi opened this issue Dec 6, 2023 · 3 comments
Closed

Make starknet.js and abiwan fully compatible #877

haroune-mohammedi opened this issue Dec 6, 2023 · 3 comments
Assignees
Labels
OnlyDust Open for OnlyDust contributors Type: feature New feature or request

Comments

@haroune-mohammedi
Copy link
Contributor

Describe the bug
While investigating keep-starknet-strange/abi-wan-kanabi#46, we realize abiwan and starketjs aren't fully compatible

To Reproduce
Run the tests in ./__tests__/cairo1_typed.test.ts

Expected behavior
All tests should pass

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Browser & version [e.g. chrome, safari, webworker]
  • Node version [e.g. 16.0.1]
  • Starknet.js version
  • Network [devnet, testnet]

Additional context

Test output

❯ npm run test ./__tests__/cairo1_typed.test.ts

> [email protected] pretest
> npm run lint && npm run ts:check


> [email protected] lint
> eslint . --cache --fix --ext .ts

=============

WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=3.3.1 <5.1.0

YOUR TYPESCRIPT VERSION: 5.1.3

Please only submit bug reports when using the officially supported version.

=============

> [email protected] ts:check
> tsc --noEmit --resolveJsonModule --project tsconfig.eslint.json


> [email protected] test
> jest -i ./__tests__/cairo1_typed.test.ts

Determining test suites to run...Global Test Setup Started
 TEST_ACCOUNT_ADDRESS env is not provided!
TEST_ACCOUNT_PRIVATE_KEY env is not provided!
Basic test parameters are missing, Auto Setup Started
Detected Devnet-RS
Detected RPC
Detected Account
┌──────────────────────────┬─────────────────────────────────────────────────────────────────────┐
│ (index)                  │ Values                                                              │
├──────────────────────────┼─────────────────────────────────────────────────────────────────────┤
│ TEST_ACCOUNT_ADDRESS     │ '0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691' │
│ TEST_ACCOUNT_PRIVATE_KEY │ '****'                                                              │
│ INITIAL_BALANCE          │ '1000000000000000000000'                                            │
│ TEST_PROVIDER_BASE_URL   │ undefined                                                           │
│ TEST_RPC_URL             │ 'http://127.0.0.1:5050/'                                            │
└──────────────────────────┴─────────────────────────────────────────────────────────────────────┘
┌─────────────────────┬─────────┐
│ (index)             │ Values  │
├─────────────────────┼─────────┤
│ IS_LOCALHOST_DEVNET │ 'true'  │
│ IS_RPC_DEVNET       │ 'true'  │
│ IS_SEQUENCER_DEVNET │ 'false' │
│ IS_RPC              │ 'true'  │
│ IS_SEQUENCER        │ 'false' │
│ IS_SEQUENCER_GOERLI │ 'false' │
└─────────────────────┴─────────┘
Global Test Environment is Ready
(node:91437) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
 FAIL  __tests__/cairo1_typed.test.ts (106.875 s)
  TS validation for API &  Contract interactions - tests skipped
    ✓ Declare & deploy v2 - Hello Cairo 1 contract (11 ms)
    ✓ ContractFactory on Cairo1 (5625 ms)
    ✓ deployContract Cairo1 (4383 ms)
    ✓ GetClassByHash (95 ms)
    ✓ GetClassAt (56 ms)
    ✓ isCairo1 (1 ms)
    ✓ Cairo 1 Contract Interaction - skip invoke validation & call parsing (5447 ms)
    ✓ Cairo 1 Contract Interaction - felt252 (5434 ms)
    ✓ Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128 (9794 ms)
    ✓ Cairo 1 - uint256 (2176 ms)
    ✓ Cairo 1 Contract Interaction - bool (16322 ms)
    ✓ Cairo 1 Contract Interaction - ContractAddress (5437 ms)
    ✓ Cairo1 simple getStorageAt variables retrieval (21739 ms)
    ✕ Cairo 1 Contract Interaction - echo flat un-named un-nested tuple (1 ms)
    ✓ Cairo 1 Contract Interaction - echo flat un-nested Array u8, uint256, bool (4344 ms)
    ✓ Cairo 1 Contract Interaction - echo flat un-nested Struct (1090 ms)
    ✕ Cairo 1 more complex structs (4313 ms)
    ✓ C1 Array 2D (13110 ms)
    ✕ mix tuples (1092 ms)
    ✓ myCallData.compile for Cairo 1 (2 ms)
    ✕ getCompiledClassByClassHash
    ○ skipped validate TS for redeclare - skip testing
  TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped
    ✕ getCompiledClassByClassHash
    ✕ GetClassByHash (1 ms)
    ✕ GetClassAt (1 ms)
    ✕ Cairo 1 Contract Interaction - felt252 (1 ms)
    ✕ Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128
    ✕ Cairo 1 - uint256 struct
    ✕ Cairo 1 - uint256 by a bignumber
    ✕ Cairo 1 Contract Interaction - bool

  ● TS validation for API &  Contract interactions - tests skipped › Cairo 1 Contract Interaction - echo flat un-named un-nested tuple

    Validate: arg a should be a tuple (defined as object)

      1 | export default function assert(condition: any, message?: string): asserts condition {
      2 |   if (!condition) {
    > 3 |     throw new Error(message || 'Assertion failure');
        |           ^
      4 |   }
      5 | }
      6 |

      at assert (src/utils/assert.ts:3:11)
      at validateTuple (src/utils/calldata/validate.ts:192:9)
      at validateTuple (src/utils/calldata/validate.ts:282:9)
          at Array.reduce (<anonymous>)
      at reduce (src/utils/calldata/validate.ts:257:20)
      at CallData.validate (src/utils/calldata/index.ts:96:19)
      at validate (src/contract/default.ts:234:23)
      at callback (src/contract/default.ts:113:10)
      at Contract.getCalldata [as call] (src/contract/default.ts:232:22)
      at Contract.call [as echo_un_tuple] (src/contract/default.ts:59:21)
      at Object.echo_un_tuple (__tests__/cairo1_typed.test.ts:228:41)

  ● TS validation for API &  Contract interactions - tests skipped › Cairo 1 more complex structs

    Invalid number of arguments, expected 1 arguments, but got 2

      88 |     const inputsLength = this.parser.methodInputsLength(abiMethod);
      89 |     if (args.length !== inputsLength) {
    > 90 |       throw Error(
         |             ^
      91 |         `Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
      92 |       );
      93 |     }

      at CallData.Error [as validate] (src/utils/calldata/index.ts:90:13)
      at validate (src/contract/default.ts:234:23)
      at callback (src/contract/default.ts:113:10)
      at Contract.getCalldata [as call] (src/contract/default.ts:232:22)
      at Contract.call [as get_bet] (src/contract/default.ts:59:21)
      at Object.get_bet (__tests__/cairo1_typed.test.ts:263:41)

  ● TS validation for API &  Contract interactions - tests skipped › mix tuples

    Validate: arg a should be a tuple (defined as object)

      1 | export default function assert(condition: any, message?: string): asserts condition {
      2 |   if (!condition) {
    > 3 |     throw new Error(message || 'Assertion failure');
        |           ^
      4 |   }
      5 | }
      6 |

      at assert (src/utils/assert.ts:3:11)
      at validateTuple (src/utils/calldata/validate.ts:192:9)
      at validateTuple (src/utils/calldata/validate.ts:282:9)
          at Array.reduce (<anonymous>)
      at reduce (src/utils/calldata/validate.ts:257:20)
      at CallData.validate (src/utils/calldata/index.ts:96:19)
      at validate (src/contract/default.ts:234:23)
      at callback (src/contract/default.ts:113:10)
      at Contract.getCalldata [as call] (src/contract/default.ts:232:22)
      at Contract.call [as tuple_echo] (src/contract/default.ts:59:21)
      at Object.tuple_echo (__tests__/cairo1_typed.test.ts:336:39)

  ● TS validation for API &  Contract interactions - tests skipped › getCompiledClassByClassHash

    TypeError: provider.getCompiledClassByClassHash is not a function

      490 |
      491 |   test('getCompiledClassByClassHash', async () => {
    > 492 |     const compiledClass = await (provider as SequencerProvider).getCompiledClassByClassHash(
          |                                                                 ^
      493 |       dd.deploy.classHash
      494 |     );
      495 |     expect(compiledClass).toMatchSchemaRef('CompiledClass');

      at Object.getCompiledClassByClassHash (__tests__/cairo1_typed.test.ts:492:65)

  ● TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped › getCompiledClassByClassHash

    TypeError: provider.getCompiledClassByClassHash is not a function

      505 |
      506 |   test('getCompiledClassByClassHash', async () => {
    > 507 |     const compiledClass = await provider.getCompiledClassByClassHash(classHash);
          |                                          ^
      508 |     expect(compiledClass).toMatchSchemaRef('CompiledClass');
      509 |   });
      510 |

      at Object.getCompiledClassByClassHash (__tests__/cairo1_typed.test.ts:507:42)

  ● TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped › GetClassByHash

    LibraryError: RPC: starknet_getClass with params {"class_hash":"0x28b6f2ee9ae00d55a32072d939a55a6eb522974a283880f3c73a64c2f9fd6d6","block_id":"pending"}
     28: Class hash not found: undefined

      106 |     if (rpcError) {
      107 |       const { code, message, data } = rpcError;
    > 108 |       throw new LibraryError(
          |             ^
      109 |         `RPC: ${method} with params ${stringify(params)}\n ${code}: ${message}: ${stringify(data)}`
      110 |       );
      111 |     }

      at RpcProvider.errorHandler (src/provider/rpc.ts:108:13)
      at RpcProvider.errorHandler [as fetchEndpoint] (src/provider/rpc.ts:127:12)
      at Object.<anonymous> (__tests__/cairo1_typed.test.ts:512:27)

  ● TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped › GetClassAt

    LibraryError: RPC: starknet_getClassAt with params {"block_id":"pending","contract_address":"0x771bbe2ba64fa5ab52f0c142b4296fc67460a3a2372b4cdce752c620e3e8194"}
     20: Contract not found: undefined

      106 |     if (rpcError) {
      107 |       const { code, message, data } = rpcError;
    > 108 |       throw new LibraryError(
          |             ^
      109 |         `RPC: ${method} with params ${stringify(params)}\n ${code}: ${message}: ${stringify(data)}`
      110 |       );
      111 |     }

      at RpcProvider.errorHandler (src/provider/rpc.ts:108:13)
      at RpcProvider.errorHandler [as fetchEndpoint] (src/provider/rpc.ts:127:12)
      at Object.<anonymous> (__tests__/cairo1_typed.test.ts:517:27)

  ● TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped › Cairo 1 Contract Interaction - felt252

    TypeError: Cannot read properties of undefined (reading 'test_felt252')

      520 |
      521 |   test('Cairo 1 Contract Interaction - felt252', async () => {
    > 522 |     const result = await cairo1Contract.test_felt252(100);
          |                                         ^
      523 |     expect(result).toBe(101n);
      524 |   });
      525 |

      at Object.test_felt252 (__tests__/cairo1_typed.test.ts:522:41)

  ● TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped › Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128

    TypeError: Cannot read properties of undefined (reading 'test_u8')

      525 |
      526 |   test('Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128', async () => {
    > 527 |     const r1 = await cairo1Contract.test_u8(100n);
          |                                     ^
      528 |     expect(r1).toBe(107n);
      529 |     const r2 = await cairo1Contract.test_u16(100n);
      530 |     expect(r2).toBe(106n);

      at Object.test_u8 (__tests__/cairo1_typed.test.ts:527:37)

  ● TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped › Cairo 1 - uint256 struct

    TypeError: Cannot read properties of undefined (reading 'test_u256')

      539 |   test('Cairo 1 - uint256 struct', async () => {
      540 |     const myUint256 = uint256(2n ** 256n - 2n);
    > 541 |     const result = await cairo1Contract.test_u256(myUint256);
          |                                         ^
      542 |     expect(result).toBe(2n ** 256n - 1n);
      543 |   });
      544 |

      at Object.test_u256 (__tests__/cairo1_typed.test.ts:541:41)

  ● TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped › Cairo 1 - uint256 by a bignumber

    TypeError: Cannot read properties of undefined (reading 'test_u256')

      544 |
      545 |   test('Cairo 1 - uint256 by a bignumber', async () => {
    > 546 |     const result = await cairo1Contract.test_u256(2n ** 256n - 2n);
          |                                         ^
      547 |     expect(result).toBe(2n ** 256n - 1n);
      548 |   });
      549 |

      at Object.test_u256 (__tests__/cairo1_typed.test.ts:546:41)

  ● TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped › Cairo 1 Contract Interaction - bool

    TypeError: Cannot read properties of undefined (reading 'test_bool')

      549 |
      550 |   test('Cairo 1 Contract Interaction - bool', async () => {
    > 551 |     const tx = await cairo1Contract.test_bool();
          |                                     ^
      552 |     expect(tx).toBe(true);
      553 |   });
      554 | });

      at Object.test_bool (__tests__/cairo1_typed.test.ts:551:37)

Test Suites: 1 failed, 1 total
Tests:       12 failed, 1 skipped, 17 passed, 30 total
Snapshots:   0 total
Time:        106.907 s, estimated 109 s
Ran all test suites matching /.\/__tests__\/cairo1_typed.test.ts/i.

@haroune-mohammedi haroune-mohammedi added the Type: bug Something isn't working label Dec 6, 2023
@haroune-mohammedi
Copy link
Contributor Author

We'll start by first debugging the failed tests, identify why they are not working and then list all incompatible types

@haroune-mohammedi
Copy link
Contributor Author

haroune-mohammedi commented Dec 7, 2023

I fixed most of the tests, there was a missing describeIfSequencerGoerli.

Only 3 tests are failing now, see output below, one because options argument is not handled correctly for some reason and the other two because of incompatible representation of tuples, abiwan uses TS tuples for that but starket.js expects an object and I'm wondering why ?

Test output

 FAIL  __tests__/cairo1_typed.test.ts (108.043 s)
  TS validation for API &  Contract interactions - tests skipped
    ✓ Declare & deploy v2 - Hello Cairo 1 contract (10 ms)
    ✓ ContractFactory on Cairo1 (5681 ms)
    ✓ deployContract Cairo1 (4394 ms)
    ✓ GetClassByHash (107 ms)
    ✓ GetClassAt (56 ms)
    ✓ isCairo1
    ✓ Cairo 1 Contract Interaction - skip invoke validation & call parsing (5443 ms)
    ✓ Cairo 1 Contract Interaction - felt252 (5446 ms)
    ✓ Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128 (9823 ms)
    ✓ Cairo 1 - uint256 (2182 ms)
    ✓ Cairo 1 Contract Interaction - bool (16320 ms)
    ✓ Cairo 1 Contract Interaction - ContractAddress (5438 ms)
    ✓ Cairo1 simple getStorageAt variables retrieval (21708 ms)
    ✕ Cairo 1 Contract Interaction - echo flat un-named un-nested tuple (1 ms)
    ✓ Cairo 1 Contract Interaction - echo flat un-nested Array u8, uint256, bool (4364 ms)
    ✓ Cairo 1 Contract Interaction - echo flat un-nested Struct (1091 ms)
    ✕ Cairo 1 more complex structs (5443 ms)
    ✓ C1 Array 2D (13059 ms)
    ✕ mix tuples (1089 ms)
    ✓ myCallData.compile for Cairo 1 (3 ms)
    ○ skipped validate TS for redeclare - skip testing
    Sequencer only
      ○ skipped getCompiledClassByClassHash
  Cairo1 Testnet
    TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped
      ○ skipped getCompiledClassByClassHash
      ○ skipped GetClassByHash
      ○ skipped GetClassAt
      ○ skipped Cairo 1 Contract Interaction - felt252
      ○ skipped Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128
      ○ skipped Cairo 1 - uint256 struct
      ○ skipped Cairo 1 - uint256 by a bignumber
      ○ skipped Cairo 1 Contract Interaction - bool

  ● TS validation for API &  Contract interactions - tests skipped › Cairo 1 Contract Interaction - echo flat un-named un-nested tuple

    Validate: arg a should be a tuple (defined as object)

      1 | export default function assert(condition: any, message?: string): asserts condition {
      2 |   if (!condition) {
    > 3 |     throw new Error(message || 'Assertion failure');
        |           ^
      4 |   }
      5 | }
      6 |

      at assert (src/utils/assert.ts:3:11)
      at validateTuple (src/utils/calldata/validate.ts:192:9)
      at validateTuple (src/utils/calldata/validate.ts:282:9)
          at Array.reduce (<anonymous>)
      at reduce (src/utils/calldata/validate.ts:257:20)
      at CallData.validate (src/utils/calldata/index.ts:96:19)
      at validate (src/contract/default.ts:234:23)
      at callback (src/contract/default.ts:113:10)
      at Contract.getCalldata [as call] (src/contract/default.ts:232:22)
      at Contract.call [as echo_un_tuple] (src/contract/default.ts:59:21)
      at Object.echo_un_tuple (__tests__/cairo1_typed.test.ts:230:41)

  ● TS validation for API &  Contract interactions - tests skipped › Cairo 1 more complex structs

    expect(received).toEqual(expected) // deep equality

    - Expected  - 2
    + Received  + 2

    @@ -8,13 +8,13 @@
          "address": 2846891009026995430665703316224827616914889274105712248413538305735679628945n,
          "is_claimed": false,
        },
        "creation_time": 1n,
        "creator": 2846891009026995430665703316224827616914889274105712248413538305735679628945n,
    -   "description": 6579555n,
    +   "description": "dec",
        "expire_date": 1n,
        "is_cancelled": false,
        "is_voted": false,
    -   "name": 1952805748n,
    +   "name": "test",
        "pool": 10n,
        "winner": false,
      }

      290 |       amount: 1000n,
      291 |     };
    > 292 |     expect(expected).toEqual(status);
          |                      ^
      293 |   });
      294 |
      295 |   test('C1 Array 2D', async () => {

      at Object.toEqual (__tests__/cairo1_typed.test.ts:292:22)

  ● TS validation for API &  Contract interactions - tests skipped › mix tuples

    Validate: arg a should be a tuple (defined as object)

      1 | export default function assert(condition: any, message?: string): asserts condition {
      2 |   if (!condition) {
    > 3 |     throw new Error(message || 'Assertion failure');
        |           ^
      4 |   }
      5 | }
      6 |

      at assert (src/utils/assert.ts:3:11)
      at validateTuple (src/utils/calldata/validate.ts:192:9)
      at validateTuple (src/utils/calldata/validate.ts:282:9)
          at Array.reduce (<anonymous>)
      at reduce (src/utils/calldata/validate.ts:257:20)
      at CallData.validate (src/utils/calldata/index.ts:96:19)
      at validate (src/contract/default.ts:234:23)
      at callback (src/contract/default.ts:113:10)
      at Contract.getCalldata [as call] (src/contract/default.ts:232:22)
      at Contract.call [as tuple_echo] (src/contract/default.ts:59:21)
      at Object.tuple_echo (__tests__/cairo1_typed.test.ts:338:39)

Test Suites: 1 failed, 1 total
Tests:       3 failed, 10 skipped, 17 passed, 30 total
Snapshots:   0 total
Time:        108.077 s
Ran all test suites matching /.\/__tests__\/cairo1_typed.test.ts/i.

@haroune-mohammedi
Copy link
Contributor Author

haroune-mohammedi commented Dec 19, 2023

So far, the incompatible types we discovered are:

  • types.Call.calldata
  • CairoOption
  • CairoResult
  • CairoCustomEnum
  • tuple

@tabaktoni tabaktoni added Type: feature New feature or request and removed Type: bug Something isn't working labels Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OnlyDust Open for OnlyDust contributors Type: feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants