Skip to content

Commit

Permalink
feat: boolean to felt - cairo 1, compile()
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Apr 25, 2023
1 parent 0b20581 commit ef34e0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion __tests__/cairo1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describeIfDevnetSequencer('Cairo 1', () => {
describe('Sequencer API', () => {
const provider = getTestProvider() as SequencerProvider;
const account = getTestAccount(provider);
let classHash: any; // = '0x5b3507904c785fcceff17b34b4269f729bbddc1a432e4a63145c70071383413';
let classHash: any; // = '0x3e2e625998f89befe4d429d5d958275f86421310bfb00440c2431140e8c90ba';
let contractAddress: any;
let declareV2Tx: any;
let cairo1Contract: Contract;
Expand Down Expand Up @@ -94,6 +94,9 @@ describeIfDevnetSequencer('Cairo 1', () => {
});

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

let tx = await cairo1Contract.set_status(true);
await account.waitForTransaction(tx.transaction_hash);
let status = await cairo1Contract.get_status();
Expand Down
4 changes: 4 additions & 0 deletions src/utils/calldata/cairo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export function felt(it: BigNumberish): string {
if (typeof it === 'string' && isStringWholeNumber(it)) {
return it;
}
// bool to felt
if (typeof it === 'boolean') {
return `${+it}`;
}

throw new Error(`${it} can't be computed by felt()`);
}

0 comments on commit ef34e0a

Please sign in to comment.