Skip to content

Commit

Permalink
test: enable abiwan integration tests
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
haroune-mohammedi committed Dec 29, 2023
1 parent e6984ad commit dba65f3
Showing 1 changed file with 101 additions and 76 deletions.
177 changes: 101 additions & 76 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 @@ -211,12 +231,12 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
// TODO: Complex mapping - https://docs.starknet.io/documentation/architecture_and_concepts/Contracts/contract-storage/
});

xtest('Cairo 1 Contract Interaction - echo flat un-named un-nested tuple', async () => {
test('Cairo 1 Contract Interaction - echo flat un-named un-nested tuple', async () => {
const status = await cairo1Contract.echo_un_tuple([77, 123]);
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,14 +257,14 @@ 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',
});
expect(shortString.decodeShortString(status.val as string)).toBe('simple');
});

xtest('Cairo 1 more complex structs', async () => {
test('Cairo 1 more complex structs', async () => {
const tx = await cairo1Contract.set_bet();
await account.waitForTransaction(tx.transaction_hash);
const status = await cairo1Contract.get_bet(
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 @@ -313,7 +333,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
expect(result1).toEqual(result11);
});

xtest('mix tuples', async () => {
test('mix tuples', async () => {
const res = await cairo1Contract.array_bool_tuple([1, 2, 3], true);
expect(res).toEqual({
0: [1n, 2n, 3n, 1n, 2n],
Expand All @@ -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);
});
});
});

0 comments on commit dba65f3

Please sign in to comment.