Skip to content

Commit

Permalink
[Feat]: Abiwan V2 Integration (#912)
Browse files Browse the repository at this point in the history
* test: enable abiwan integration tests

They were disabled for some reason, we have to execute them to make
sure the integration is working as expected at runtime and not only
at compile time (type inference)

* feat: abiwan v2 intergation

* test: abiwan v2 integration

* chore: skip abiwan integration v1 failing tests

Those will be addressed later

* chore: use abi-wan-kanabi version 2.1.0-rc.1

* feat: make Abi and CONTRACT_ABI types compatible with abiwan

* chore: use abi-wan-kanabi version 2.1.0
  • Loading branch information
haroune-mohammedi authored Jan 15, 2024
1 parent dd414e1 commit 8468e2f
Show file tree
Hide file tree
Showing 9 changed files with 2,083 additions and 79 deletions.
978 changes: 978 additions & 0 deletions __mocks__/hellov2.ts

Large diffs are not rendered by default.

171 changes: 98 additions & 73 deletions __tests__/cairo1_typed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
compiledComplexSierra,
compiledHelloSierra,
compiledHelloSierraCasm,
describeIfDevnetSequencer,
describeIfSequencerGoerli,
getTestAccount,
getTestProvider,
} from './fixtures';
Expand All @@ -36,13 +38,31 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
let cairo1Contract: TypedContract<typeof tAbi>;
initializeMatcher(expect);

xtest('Declare & deploy v2 - Hello Cairo 1 contract', async () => {
beforeAll(async () => {
dd = await account.declareAndDeploy({
contract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
});

cairo1Contract = new Contract(
compiledHelloSierra.abi,
dd.deploy.contract_address,
account
).typed(tAbi);
});

test('Declare & deploy v2 - Hello Cairo 1 contract', async () => {
expect(dd.declare).toMatchSchemaRef('DeclareContractResponse');
expect(dd.deploy).toMatchSchemaRef('DeployContractUDCResponse');
expect(cairo1Contract).toBeInstanceOf(Contract);
});

xtest('ContractFactory on Cairo1', async () => {
test('getCairoVersion', async () => {
const version1 = await cairo1Contract.getVersion();
expect(version1).toEqual({ cairo: '1', compiler: '1' });
});

test('ContractFactory on Cairo1', async () => {
const c1CFactory = new ContractFactory({
compiledContract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
Expand All @@ -67,53 +87,53 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
});
});

xtest('deployContract Cairo1', async () => {
test('deployContract Cairo1', async () => {
const deploy = await account.deployContract({
classHash: dd.deploy.classHash,
});
expect(deploy).toHaveProperty('address');
});

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

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

xtest('isCairo1', async () => {
test('isCairo1', async () => {
const isContractCairo1 = cairo1Contract.isCairo1();
expect(isContractCairo1).toBe(true);
const isAbiCairo1 = isCairo1Abi(cairo1Contract.abi);
expect(isAbiCairo1).toBe(true);
});

xtest('Cairo 1 Contract Interaction - skip invoke validation & call parsing', async () => {
test('Cairo 1 Contract Interaction - skip invoke validation & call parsing', async () => {
const tx = await cairo1Contract.increase_balance(
CallData.compile({
amount: 100,
})
);
await account.waitForTransaction(tx.transaction_hash);

// const balance = await cairo1Contract.get_balance({
// parseResponse: false,
// });
const balance = await cairo1Contract.get_balance({
parseResponse: false,
});

// expect(num.toBigInt(balance[0])).toBe(100n);
expect(num.toBigInt(balance)).toBe(100n);
});

xtest('Cairo 1 Contract Interaction - felt252', async () => {
test('Cairo 1 Contract Interaction - felt252', async () => {
const tx = await cairo1Contract.increase_balance(100);
await account.waitForTransaction(tx.transaction_hash);
const balance = await cairo1Contract.get_balance();
expect(balance).toBe(200n);
});

xtest('Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128', async () => {
test('Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128', async () => {
const tx = await cairo1Contract.increase_balance_u8(255n);
await account.waitForTransaction(tx.transaction_hash);
const balance = await cairo1Contract.get_balance_u8();
Expand All @@ -129,7 +149,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
expect(result).toBe(256n);
});

xtest('Cairo 1 - uint256', async () => {
test('Cairo 1 - uint256', async () => {
// defined as number
const result = await cairo1Contract.test_u256(2n ** 256n - 2n);
expect(result).toBe(2n ** 256n - 1n);
Expand All @@ -139,7 +159,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
expect(result1).toBe(2n ** 256n - 1n);
});

xtest('Cairo 1 Contract Interaction - bool', async () => {
test('Cairo 1 Contract Interaction - bool', async () => {
const cdata = CallData.compile({ false: false, true: true });
expect(cdata).toEqual(['0', '1']);

Expand All @@ -162,15 +182,15 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
expect(status).toBe(true);
});

xtest('Cairo 1 Contract Interaction - ContractAddress', async () => {
test('Cairo 1 Contract Interaction - ContractAddress', async () => {
const tx = await cairo1Contract.set_ca('123');
await account.waitForTransaction(tx.transaction_hash);
const status = await cairo1Contract.get_ca();

expect(status).toBe(123n);
});

xtest('Cairo1 simple getStorageAt variables retrieval', async () => {
test('Cairo1 simple getStorageAt variables retrieval', async () => {
// u8
let tx = await cairo1Contract.increase_balance(100);
await account.waitForTransaction(tx.transaction_hash);
Expand Down Expand Up @@ -216,7 +236,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
expect(Object.values(status)).toEqual([77n, 123n]);
});

xtest('Cairo 1 Contract Interaction - echo flat un-nested Array u8, uint256, bool', async () => {
test('Cairo 1 Contract Interaction - echo flat un-nested Array u8, uint256, bool', async () => {
const status = await cairo1Contract.echo_array([123, 55, 77, 255]);
expect(status).toEqual([123n, 55n, 77n, 255n]);

Expand All @@ -237,7 +257,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
expect(status2).toEqual([true, true, false, false]);
});

xtest('Cairo 1 Contract Interaction - echo flat un-nested Struct', async () => {
test('Cairo 1 Contract Interaction - echo flat un-nested Struct', async () => {
const status = await cairo1Contract.echo_struct({
val: 'simple',
});
Expand Down Expand Up @@ -277,7 +297,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
expect(expected).toEqual(status);
});

xtest('C1 Array 2D', async () => {
test('C1 Array 2D', async () => {
const cd = CallData.compile({
test: [
[1, 2],
Expand Down Expand Up @@ -330,7 +350,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
});
});

xtest('myCallData.compile for Cairo 1', async () => {
test('myCallData.compile for Cairo 1', async () => {
const myFalseUint256 = { high: 1, low: 23456 }; // wrong order
type Order2 = {
p1: BigNumberish;
Expand Down Expand Up @@ -475,67 +495,72 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
expect(callDataFromArray).toStrictEqual(expectedResult);
});

xtest('getCompiledClassByClassHash', async () => {
const compiledClass = await (provider as SequencerProvider).getCompiledClassByClassHash(
dd.deploy.classHash
);
expect(compiledClass).toMatchSchemaRef('CompiledClass');
describeIfDevnetSequencer('Sequencer only', () => {
test('getCompiledClassByClassHash', async () => {
const compiledClass = await (provider as SequencerProvider).getCompiledClassByClassHash(
dd.deploy.classHash
);
expect(compiledClass).toMatchSchemaRef('CompiledClass');
});
});
});

describe('TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped', () => {
const provider = getTestProvider() as SequencerProvider;
const classHash: any = '0x028b6f2ee9ae00d55a32072d939a55a6eb522974a283880f3c73a64c2f9fd6d6';
const contractAddress: any = '0x771bbe2ba64fa5ab52f0c142b4296fc67460a3a2372b4cdce752c620e3e8194';
let cairo1Contract: TypedContract<typeof tAbi>;
initializeMatcher(expect);

xtest('getCompiledClassByClassHash', async () => {
const compiledClass = await provider.getCompiledClassByClassHash(classHash);
expect(compiledClass).toMatchSchemaRef('CompiledClass');
});
describeIfSequencerGoerli('Cairo1 Testnet', () => {
describe('TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped', () => {
const provider = getTestProvider() as SequencerProvider;
const classHash: any = '0x028b6f2ee9ae00d55a32072d939a55a6eb522974a283880f3c73a64c2f9fd6d6';
const contractAddress: any =
'0x771bbe2ba64fa5ab52f0c142b4296fc67460a3a2372b4cdce752c620e3e8194';
let cairo1Contract: TypedContract<typeof tAbi>;
initializeMatcher(expect);

test('getCompiledClassByClassHash', async () => {
const compiledClass = await provider.getCompiledClassByClassHash(classHash);
expect(compiledClass).toMatchSchemaRef('CompiledClass');
});

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

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

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

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

xtest('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 struct', async () => {
const myUint256 = uint256(2n ** 256n - 2n);
const result = await cairo1Contract.test_u256(myUint256);
expect(result).toBe(2n ** 256n - 1n);
});

xtest('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 - uint256 by a bignumber', async () => {
const result = await cairo1Contract.test_u256(2n ** 256n - 2n);
expect(result).toBe(2n ** 256n - 1n);
});

xtest('Cairo 1 Contract Interaction - bool', async () => {
const tx = await cairo1Contract.test_bool();
expect(tx).toBe(true);
test('Cairo 1 Contract Interaction - bool', async () => {
const tx = await cairo1Contract.test_bool();
expect(tx).toBe(true);
});
});
});
Loading

0 comments on commit 8468e2f

Please sign in to comment.