diff --git a/src/contract-types-plugin-e2e-tests.spec.ts b/src/contract-types-plugin-e2e-tests.spec.ts new file mode 100644 index 0000000..2722d18 --- /dev/null +++ b/src/contract-types-plugin-e2e-tests.spec.ts @@ -0,0 +1,292 @@ +import { exec as exec1 } from 'child_process'; +import path from 'path'; +import util from 'util'; +const exec = util.promisify(exec1); + +import { prepareEnvironment } from '@gmrchk/cli-testing-library'; + +describe('Contract Types Plugin E2E Testing for Taqueria CLI', () => { + + jest.setTimeout(30000); + + test('contract types plugin will offer help', async () => { + const { execute, spawn, cleanup } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + + const { stdout: stdout2 } = await execute('taq', '--help --projectDir=./test-project'); + expect(stdout2).toEqual(expect.arrayContaining(['Commands:'])); + + await cleanup(); + }); + + test.skip('1635 - generate types offers contextual help', async () => { + const { execute, spawn, cleanup } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + + const { stdout: stdout2 } = await execute('taq', 'generate types --help --projectDir=./test-project'); + expect(stdout2).toEqual(expect.arrayContaining(['Generate types for a contract to be used with taquito'])); + + await cleanup(); + }); + + test.skip('1635 - gen offers contextual help', async () => { + const { execute, spawn, cleanup } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + + const { stdout: stdout2 } = await execute('taq', 'gen --help --projectDir=./test-project'); + expect(stdout2).toEqual(expect.arrayContaining(['Generate types for a contract to be used with taquito'])); + + await cleanup(); + }); + + test('generate types will only output the typeScriptDir and will not create a types dir when no contracts exist', async () => { + const { execute, spawn, cleanup, ls } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + + const { stdout: stdout1 } = await execute('taq', 'generate types', './test-project'); + expect(stdout1).toContain(`generateTypes { typescriptDir: 'types' }`); + + expect(await ls('./test-project/')).not.toContain('types'); + + await cleanup(); + }); + + test('generate types types can compile one contract and generate types', async () => { + const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); + expect(stdout1).toContain('Plugin installed successfully'); + + const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout; + await writeFile('./test-project/contracts/increment.jsligo', jsligo_file); + + const {} = await execute('taq', 'compile increment.jsligo', './test-project'); + + const { stdout: stdout2 } = await execute('taq', 'generate types types', './test-project'); + expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`); + expect(stdout2).toEqual( + expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']), + ); + expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:'])); + expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz'])); + expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...'])); + expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated'])); + + expect(await ls('./test-project/')).toContain('types'); + expect(await ls('./test-project/types')).toContain('increment.code.ts'); + expect(await ls('./test-project/types')).toContain('increment.types.ts'); + expect(await ls('./test-project/types')).toContain('type-aliases.ts'); + expect(await ls('./test-project/types')).toContain('type-utils.ts'); + + await cleanup(); + }); + + test('gentypes types can compile one contract and generate types', async () => { + const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); + expect(stdout1).toContain('Plugin installed successfully'); + + const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout; + await writeFile('./test-project/contracts/increment.jsligo', jsligo_file); + + const {} = await execute('taq', 'compile increment.jsligo', './test-project'); + + const { stdout: stdout2 } = await execute('taq', 'gentypes types', './test-project'); + expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`); + expect(stdout2).toEqual( + expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']), + ); + expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:'])); + expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz'])); + expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...'])); + expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated'])); + + expect(await ls('./test-project/')).toContain('types'); + expect(await ls('./test-project/types')).toContain('increment.code.ts'); + expect(await ls('./test-project/types')).toContain('increment.types.ts'); + expect(await ls('./test-project/types')).toContain('type-aliases.ts'); + expect(await ls('./test-project/types')).toContain('type-utils.ts'); + + await cleanup(); + }); + + test('gen types can compile one contract and generate types', async () => { + const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); + expect(stdout1).toContain('Plugin installed successfully'); + + const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout; + await writeFile('./test-project/contracts/increment.jsligo', jsligo_file); + + const {} = await execute('taq', 'compile increment.jsligo', './test-project'); + + const { stdout: stdout2 } = await execute('taq', 'gen types', './test-project'); + expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`); + expect(stdout2).toEqual( + expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']), + ); + expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:'])); + expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz'])); + expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...'])); + expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated'])); + + expect(await ls('./test-project/')).toContain('types'); + expect(await ls('./test-project/types')).toContain('increment.code.ts'); + expect(await ls('./test-project/types')).toContain('increment.types.ts'); + expect(await ls('./test-project/types')).toContain('type-aliases.ts'); + expect(await ls('./test-project/types')).toContain('type-utils.ts'); + + await cleanup(); + }); + + test('generate types -t "file" can compile one contract and generate types', async () => { + const { execute, cleanup, spawn, writeFile, ls } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); + expect(stdout1).toContain('Plugin installed successfully'); + + const jsligo_file = await (await exec(`cat src/test-data/increment.jsligo`)).stdout; + await writeFile('./test-project/contracts/increment.jsligo', jsligo_file); + + const {} = await execute('taq', 'compile increment.jsligo', './test-project'); + + const { stdout: stdout2 } = await execute('taq', 'generate types -t "file"', './test-project'); + expect(stdout2).toContain(`generateTypes { typescriptDir: 'types' }`); + expect(stdout2).toEqual( + expect.arrayContaining(['Generating Types: {{base}}/test-project/artifacts => {{base}}/test-project/types']), + ); + expect(stdout2).toEqual(expect.arrayContaining(['Contracts Found:'])); + expect(stdout2).toEqual(expect.arrayContaining(['- {{base}}/test-project/artifacts/increment.tz'])); + expect(stdout2).toEqual(expect.arrayContaining(['Processing /increment.tz...'])); + expect(stdout2).toEqual(expect.arrayContaining(['increment.tz: Types generated'])); + + expect(await ls('./test-project/')).toContain('types'); + expect(await ls('./test-project/types')).toContain('increment.code.ts'); + expect(await ls('./test-project/types')).toContain('increment.types.ts'); + expect(await ls('./test-project/types')).toContain('type-aliases.ts'); + expect(await ls('./test-project/types')).toContain('type-utils.ts'); + + await cleanup(); + }); + + test('generate types can compile an Auction contract and generate types', async () => { + const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); + expect(stdout1).toContain('Plugin installed successfully'); + + const tz_file = await (await exec(`cat src/test-data/contracts/example-contract-1.tz`)) + .stdout; + await writeFile('./test-project/artifacts/example-contract-1.tz', tz_file); + const expected_types_file = + await (await exec(`cat src/test-data/types-file/example-contract-1.types.ts`)).stdout; + + const {} = await execute('taq', 'generate types', './test-project'); + const generated_types_file = await readFile(path.join('./test-project', 'types', 'example-contract-1.types.ts')); + + expect(generated_types_file).toBe(expected_types_file); + + await cleanup(); + }); + + test('generate types can compile an FA2 contract and generate types', async () => { + const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); + expect(stdout1).toContain('Plugin installed successfully'); + + const tz_file = await (await exec(`cat src/test-data/contracts/example-contract-2.tz`)) + .stdout; + await writeFile('./test-project/artifacts/example-contract-2.tz', tz_file); + const expected_types_file = + await (await exec(`cat src/test-data/types-file/example-contract-2.types.ts`)).stdout; + + const {} = await execute('taq', 'generate types', './test-project'); + const generated_types_file = await readFile(path.join('./test-project', 'types', 'example-contract-2.types.ts')); + + expect(generated_types_file).toBe(expected_types_file); + + await cleanup(); + }); + + test('generate types can compile a contract from a sub-directory and generate types', async () => { + const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); + expect(stdout1).toContain('Plugin installed successfully'); + + const tz_file = + await (await exec(`cat src/test-data/contracts/subdir/example-contract-0.tz`)).stdout; + await writeFile('./test-project/artifacts/subdir/example-contract-0.tz', tz_file); + const expected_types_file = + await (await exec(`cat src/test-data/types-file/subdir/example-contract-0.types.ts`)) + .stdout; + + const {} = await execute('taq', 'generate types', './test-project'); + const generated_types_file = await readFile( + path.join('./test-project', 'types', 'subdir/example-contract-0.types.ts'), + ); + + expect(generated_types_file).toBe(expected_types_file); + + await cleanup(); + }); + + test('generate types can compile a Lambda contract and generate types', async () => { + const { execute, cleanup, spawn, writeFile, readFile } = await prepareEnvironment(); + const { waitForText } = await spawn('taq', 'init test-project'); + await waitForText("Project taq'ified!"); + const { stdout } = await execute('taq', 'install @taqueria/plugin-contract-types', './test-project'); + expect(stdout).toContain('Plugin installed successfully'); + const { stdout: stdout1 } = await execute('taq', 'install @taqueria/plugin-ligo', './test-project'); + expect(stdout1).toContain('Plugin installed successfully'); + + const tz_file = await (await exec(`cat src/test-data/contracts/example-lambda.tz`)) + .stdout; + await writeFile('./test-project/artifacts/example-lambda.tz', tz_file); + const expected_types_file = + await (await exec(`cat src/test-data/types-file/example-lambda.types.ts`)).stdout; + + const {} = await execute('taq', 'generate types', './test-project'); + const generated_types_file = await readFile(path.join('./test-project', 'types', 'example-lambda.types.ts')); + + expect(generated_types_file).toBe(expected_types_file); + + await cleanup(); + }); +}); diff --git a/src/metadata-plugin-e2e-tests.spec.ts b/src/metadata-plugin-e2e-tests.spec.ts index 97091c6..2495ce0 100644 --- a/src/metadata-plugin-e2e-tests.spec.ts +++ b/src/metadata-plugin-e2e-tests.spec.ts @@ -7,7 +7,7 @@ import { prepareEnvironment } from '@gmrchk/cli-testing-library'; describe('Metadata Plugin E2E Testing for the Taqueria CLI', () => { - jest.setTimeout(120000); + jest.setTimeout(90000); test('generate-project-metadata will add a metadata entry to the config.json', async () => { const { execute, spawn, cleanup, ls, writeFile, readFile } = await prepareEnvironment(); @@ -58,10 +58,10 @@ describe('Metadata Plugin E2E Testing for the Taqueria CLI', () => { 'authors': [ 'KentBeck', 'MartinFowler', - 'ErichGamma' + 'ErichGamma', ], 'homepage': 'http://taqueria.io', - 'license': '007' + 'license': '007', }); await cleanup(); @@ -140,10 +140,12 @@ describe('Metadata Plugin E2E Testing for the Taqueria CLI', () => { 'homepage': 'http://taqueria.io', 'license': '007', 'interfaces': [ - 'TZIP-016' - ] + 'TZIP-016', + ], }); await cleanup(); + }); -}); \ No newline at end of file +}); + diff --git a/src/test-data/contracts/example-contract-1.tz b/src/test-data/contracts/example-contract-1.tz new file mode 100644 index 0000000..8d33afa --- /dev/null +++ b/src/test-data/contracts/example-contract-1.tz @@ -0,0 +1,1409 @@ +{ parameter + (or (or (or (or %admin (or (unit %confirm_admin) (bool %pause)) (address %set_admin)) + (nat %bid)) + (or (nat %cancel) + (pair %configure + (mutez %opening_price) + (pair (nat %min_raise_percent) + (pair (mutez %min_raise) + (pair (nat %round_time) + (pair (nat %extend_time) + (pair (list %asset + (pair (address %fa2_address) (list %fa2_batch (pair (nat %token_id) (nat %amount))))) + (pair (timestamp %start_time) (timestamp %end_time)))))))))) + (nat %resolve)) ; + storage + (pair (option %pauseable_admin + (pair (pair (address %admin) (bool %paused)) (option %pending_admin address))) + (pair (nat %current_id) + (pair (nat %max_auction_time) + (pair (nat %max_config_to_start_time) + (big_map %auctions + nat + (pair (address %seller) + (pair (mutez %current_bid) + (pair (timestamp %start_time) + (pair (timestamp %last_bid_time) + (pair (int %round_time) + (pair (int %extend_time) + (pair (list %asset + (pair (address %fa2_address) (list %fa2_batch (pair (nat %token_id) (nat %amount))))) + (pair (nat %min_raise_percent) + (pair (mutez %min_raise) (pair (timestamp %end_time) (address %highest_bidder)))))))))))))))) ; + code { LAMBDA + (option (pair (pair address bool) (option address))) + (lambda (option string) unit) + { LAMBDA + (pair (option (pair (pair address bool) (option address))) (option string)) + unit + { DUP ; + CDR ; + SWAP ; + CAR ; + IF_NONE + { DROP ; UNIT } + { CAR ; + CAR ; + SENDER ; + COMPARE ; + NEQ ; + IF { IF_NONE + { PUSH string "NOT_AN_ADMIN" ; FAILWITH } + { PUSH string " " ; CONCAT ; PUSH string "NOT_AN_ADMIN" ; CONCAT ; FAILWITH } } + { DROP ; UNIT } } } ; + SWAP ; + APPLY } ; + LAMBDA + (option (pair (pair address bool) (option address))) + unit + { IF_NONE + { UNIT } + { CAR ; CDR ; IF { PUSH string "PAUSED" ; FAILWITH } { UNIT } } } ; + LAMBDA + (pair bool string) + unit + { UNPAIR ; NOT ; IF { FAILWITH } { DROP ; UNIT } } ; + LAMBDA + (pair (pair (list (pair address (list (pair nat nat)))) address) address) + (list operation) + { UNPAIR ; + UNPAIR ; + MAP { DIG 2 ; + DUP ; + DUG 3 ; + DIG 2 ; + DUP ; + DUG 3 ; + PAIR ; + LAMBDA + (pair (pair address address) (pair address (list (pair nat nat)))) + operation + { DUP ; + CDR ; + SWAP ; + CAR ; + DUP ; + CDR ; + SWAP ; + CAR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + MAP { DIG 2 ; DUP ; DUG 3 ; PAIR } ; + DIG 2 ; + DROP ; + NIL (pair address (list (pair address (pair nat nat)))) ; + SWAP ; + DIG 2 ; + PAIR ; + CONS ; + SWAP ; + CAR ; + CONTRACT %transfer + (list (pair (address %from_) + (list %txs (pair (address %to_) (pair (nat %token_id) (nat %amount)))))) ; + IF_NONE { PUSH string "Invalid FA2 Address" ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 2 ; + TRANSFER_TOKENS } ; + SWAP ; + APPLY ; + SWAP ; + EXEC } ; + SWAP ; + DROP ; + SWAP ; + DROP } ; + LAMBDA + (pair nat + (pair (option (pair (pair address bool) (option address))) + (pair nat + (pair nat + (pair nat + (big_map + nat + (pair address + (pair mutez + (pair timestamp + (pair timestamp + (pair int + (pair int + (pair (list (pair address (list (pair nat nat)))) + (pair nat (pair mutez (pair timestamp address)))))))))))))))) + (pair address + (pair mutez + (pair timestamp + (pair timestamp + (pair int + (pair int + (pair (list (pair address (list (pair nat nat)))) + (pair nat (pair mutez (pair timestamp address)))))))))) + { UNPAIR ; + SWAP ; + CDR ; + CDR ; + CDR ; + CDR ; + SWAP ; + GET ; + IF_NONE + { PUSH string "Auction does not exist for given asset_id" ; FAILWITH } + {} } ; + LAMBDA + address + (contract unit) + { CONTRACT unit ; + IF_NONE + { PUSH string "Return address does not resolve to contract" ; FAILWITH } + {} } ; + LAMBDA + (pair address + (pair mutez + (pair timestamp + (pair timestamp + (pair int + (pair int + (pair (list (pair address (list (pair nat nat)))) + (pair nat (pair mutez (pair timestamp address)))))))))) + bool + { DUP ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CAR ; + ADD ; + NOW ; + COMPARE ; + GT ; + SWAP ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + NOW ; + COMPARE ; + GE ; + OR } ; + DIG 7 ; + UNPAIR ; + IF_LEFT + { IF_LEFT + { DIG 5 ; + DROP ; + IF_LEFT + { DIG 2 ; + DROP ; + DIG 2 ; + DROP ; + DIG 2 ; + DROP ; + DIG 3 ; + DROP ; + PUSH string "Amount must be 0mutez" ; + PUSH mutez 0 ; + AMOUNT ; + COMPARE ; + EQ ; + PAIR ; + DIG 3 ; + SWAP ; + EXEC ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + SWAP ; + IF_LEFT + { IF_LEFT + { DROP ; + DIG 2 ; + DROP ; + IF_NONE + { PUSH string "NO_ADMIN_CAPABILITIES_CONFIGURED" ; FAILWITH } + { DUP ; + CDR ; + IF_NONE + { DROP ; PUSH string "NO_PENDING_ADMIN" ; FAILWITH } + { SENDER ; + COMPARE ; + EQ ; + IF { NONE address ; SWAP ; CAR ; CDR ; SENDER ; PAIR ; PAIR ; SOME } + { DROP ; PUSH string "NOT_A_PENDING_ADMIN" ; FAILWITH } } } ; + NIL operation ; + PAIR } + { SWAP ; + DUP ; + DUG 2 ; + DIG 4 ; + SWAP ; + EXEC ; + DROP ; + SWAP ; + IF_NONE + { DROP ; PUSH string "NO_ADMIN_CAPABILITIES_CONFIGURED" ; FAILWITH } + { DUP ; CDR ; DUG 2 ; CAR ; CAR ; PAIR ; PAIR ; SOME } ; + NIL operation ; + PAIR } } + { SWAP ; + DUP ; + DUG 2 ; + DIG 4 ; + SWAP ; + EXEC ; + DROP ; + SWAP ; + IF_NONE + { DROP ; PUSH string "NO_ADMIN_CAPABILITIES_CONFIGURED" ; FAILWITH } + { SWAP ; SOME ; SWAP ; CAR ; PAIR ; SOME } ; + NIL operation ; + PAIR } ; + UNPAIR ; + DIG 2 ; + CDR ; + DIG 2 ; + PAIR ; + SWAP ; + PAIR } + { DIG 7 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + SWAP ; + DUP ; + DUG 2 ; + PAIR ; + DIG 5 ; + SWAP ; + EXEC ; + PUSH string "Bidder must be an implicit account" ; + SOURCE ; + SENDER ; + COMPARE ; + EQ ; + PAIR ; + DIG 6 ; + DUP ; + DUG 7 ; + SWAP ; + EXEC ; + DROP ; + DIG 2 ; + DUP ; + DUG 3 ; + CAR ; + DIG 7 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "Auction must be in progress" ; + SWAP ; + DUP ; + DUG 2 ; + DIG 5 ; + SWAP ; + EXEC ; + NOT ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CAR ; + NOW ; + COMPARE ; + GE ; + AND ; + PAIR ; + DIG 5 ; + DUP ; + DUG 6 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "Seller cannot place a bid" ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + SENDER ; + COMPARE ; + NEQ ; + PAIR ; + DIG 5 ; + SWAP ; + EXEC ; + DROP ; + DUP ; + CAR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + COMPARE ; + EQ ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + AMOUNT ; + COMPARE ; + GE ; + AND ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CAR ; + ADD ; + AMOUNT ; + COMPARE ; + GE ; + PUSH nat 100 ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CAR ; + DIG 4 ; + DUP ; + DUG 5 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + MUL ; + EDIV ; + IF_NONE + { PUSH string "DIVISION_BY_ZERO" ; FAILWITH } + { UNPAIR ; + PUSH mutez 0 ; + DIG 2 ; + COMPARE ; + GT ; + IF { PUSH mutez 1 ; ADD } {} } ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CAR ; + ADD ; + AMOUNT ; + COMPARE ; + GE ; + OR ; + OR ; + NOT ; + IF { NOW ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CAR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + PAIR ; + AMOUNT ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CAR ; + PAIR ; + PAIR ; + PAIR ; + PUSH string "Invalid Bid amount" ; + PAIR ; + FAILWITH } + {} ; + DUP ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + DIG 4 ; + SWAP ; + EXEC ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + UNIT ; + TRANSFER_TOKENS ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + NOW ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + SUB ; + COMPARE ; + LE ; + IF { SWAP ; DUP ; DUG 2 ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR ; NOW ; ADD } + { SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR } ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + AMOUNT ; + PAIR ; + DIG 3 ; + CAR ; + PAIR ; + SENDER ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + PAIR ; + SWAP ; + CAR ; + PAIR ; + DUP ; + CDR ; + CDR ; + CDR ; + CDR ; + NOW ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + PAIR ; + SWAP ; + CAR ; + PAIR ; + DUP ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + DIG 2 ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + PAIR ; + SWAP ; + CAR ; + PAIR ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CDR ; + CDR ; + CDR ; + SWAP ; + SOME ; + DIG 3 ; + UPDATE ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CAR ; + PAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CAR ; + PAIR ; + DIG 2 ; + CAR ; + PAIR ; + NIL operation ; + DIG 2 ; + CONS ; + PAIR } } + { IF_LEFT + { DIG 8 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + DIG 8 ; + SWAP ; + EXEC ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + SWAP ; + DUP ; + DUG 2 ; + PAIR ; + DIG 5 ; + SWAP ; + EXEC ; + PUSH string "Only seller can cancel auction" ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + PAIR ; + DIG 7 ; + DUP ; + DUG 8 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "Auction must not have ended" ; + SWAP ; + DUP ; + DUG 2 ; + DIG 5 ; + SWAP ; + EXEC ; + NOT ; + PAIR ; + DIG 6 ; + DUP ; + DUG 7 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "Amount must be 0mutez" ; + PUSH mutez 0 ; + AMOUNT ; + COMPARE ; + EQ ; + PAIR ; + DIG 6 ; + SWAP ; + EXEC ; + DROP ; + DUP ; + CAR ; + SELF_ADDRESS ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + PAIR ; + DIG 5 ; + SWAP ; + EXEC ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + DIG 5 ; + SWAP ; + EXEC ; + DIG 2 ; + CDR ; + CAR ; + UNIT ; + TRANSFER_TOKENS ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CDR ; + CDR ; + CDR ; + DIG 3 ; + NONE (pair address + (pair mutez + (pair timestamp + (pair timestamp + (pair int + (pair int + (pair (list (pair address (list (pair nat nat)))) + (pair nat (pair mutez (pair timestamp address)))))))))) ; + SWAP ; + UPDATE ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CDR ; + CAR ; + PAIR ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CAR ; + PAIR ; + DIG 3 ; + CAR ; + PAIR ; + DUG 2 ; + CONS ; + PAIR } + { DIG 2 ; + DROP ; + DIG 2 ; + DROP ; + DIG 2 ; + DROP ; + NONE string ; + DIG 2 ; + DUP ; + DUG 3 ; + CAR ; + DIG 7 ; + SWAP ; + EXEC ; + SWAP ; + EXEC ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + DIG 5 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "end_time must be after start_time" ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + COMPARE ; + GT ; + PAIR ; + DIG 4 ; + DUP ; + DUG 5 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "Auction time must be less than max_auction_time" ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CAR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + SUB ; + ABS ; + COMPARE ; + LE ; + PAIR ; + DIG 4 ; + DUP ; + DUG 5 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "Start_time must not have already passed" ; + NOW ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + COMPARE ; + GE ; + PAIR ; + DIG 4 ; + DUP ; + DUG 5 ; + SWAP ; + EXEC ; + DROP ; + PUSH string + "start_time must not be greater than the sum of current time and max_config_to_start_time" ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CAR ; + NOW ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + SUB ; + ABS ; + COMPARE ; + LE ; + PAIR ; + DIG 4 ; + DUP ; + DUG 5 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "Opening price must be greater than 0mutez" ; + PUSH mutez 0 ; + DIG 2 ; + DUP ; + DUG 3 ; + CAR ; + COMPARE ; + GT ; + PAIR ; + DIG 4 ; + DUP ; + DUG 5 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "Amount must be equal to opening_price" ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + AMOUNT ; + COMPARE ; + EQ ; + PAIR ; + DIG 4 ; + DUP ; + DUG 5 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "Round_time must be greater than 0 seconds" ; + PUSH nat 0 ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CAR ; + COMPARE ; + GT ; + PAIR ; + DIG 4 ; + SWAP ; + EXEC ; + DROP ; + SENDER ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + INT ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CAR ; + INT ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + PAIR ; + SENDER ; + PAIR ; + SELF_ADDRESS ; + SENDER ; + DIG 3 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + PAIR ; + DIG 3 ; + SWAP ; + EXEC ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CDR ; + DIG 2 ; + SOME ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CAR ; + UPDATE ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CAR ; + PAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CAR ; + PAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + CAR ; + PAIR ; + DUP ; + CDR ; + CDR ; + PUSH nat 1 ; + DIG 4 ; + CDR ; + CAR ; + ADD ; + PAIR ; + SWAP ; + CAR ; + PAIR ; + SWAP ; + PAIR } } } + { DIG 8 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + DIG 8 ; + SWAP ; + EXEC ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + SWAP ; + DUP ; + DUG 2 ; + PAIR ; + DIG 5 ; + SWAP ; + EXEC ; + PUSH string "Auction must have ended" ; + SWAP ; + DUP ; + DUG 2 ; + DIG 5 ; + SWAP ; + EXEC ; + PAIR ; + DIG 6 ; + DUP ; + DUG 7 ; + SWAP ; + EXEC ; + DROP ; + PUSH string "Amount must be 0mutez" ; + PUSH mutez 0 ; + AMOUNT ; + COMPARE ; + EQ ; + PAIR ; + DIG 6 ; + SWAP ; + EXEC ; + DROP ; + DUP ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + SELF_ADDRESS ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + PAIR ; + DIG 5 ; + SWAP ; + EXEC ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + DIG 5 ; + SWAP ; + EXEC ; + DIG 2 ; + CDR ; + CAR ; + UNIT ; + TRANSFER_TOKENS ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CDR ; + CDR ; + CDR ; + DIG 3 ; + NONE (pair address + (pair mutez + (pair timestamp + (pair timestamp + (pair int + (pair int + (pair (list (pair address (list (pair nat nat)))) + (pair nat (pair mutez (pair timestamp address)))))))))) ; + SWAP ; + UPDATE ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CDR ; + CDR ; + CAR ; + PAIR ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CDR ; + CAR ; + PAIR ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CAR ; + PAIR ; + DIG 3 ; + CAR ; + PAIR ; + DUG 2 ; + CONS ; + PAIR } } } + diff --git a/src/test-data/contracts/example-contract-2.tz b/src/test-data/contracts/example-contract-2.tz new file mode 100644 index 0000000..f6407e4 --- /dev/null +++ b/src/test-data/contracts/example-contract-2.tz @@ -0,0 +1,798 @@ +{ parameter + (or (or (or %admin (or (unit %confirm_admin) (bool %pause)) (address %set_admin)) + (or %assets + (or (pair %balance_of + (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) + (list %transfer + (pair (address %from_) + (list %txs (pair (address %to_) (pair (nat %token_id) (nat %amount))))))) + (list %update_operators + (or (pair %add_operator (address %owner) (pair (address %operator) (nat %token_id))) + (pair %remove_operator (address %owner) (pair (address %operator) (nat %token_id))))))) + (or %tokens + (or (list %burn_tokens (pair (address %owner) (pair (nat %token_id) (nat %amount)))) + (pair %create_token (nat %token_id) (map %token_info string bytes))) + (list %mint_tokens (pair (address %owner) (pair (nat %token_id) (nat %amount)))))) ; + storage + (pair (pair (option %admin + (pair (pair (address %admin) (bool %paused)) (option %pending_admin address))) + (pair %assets + (pair (big_map %ledger (pair address nat) nat) + (big_map %operators (pair address (pair address nat)) unit)) + (pair (big_map %token_metadata nat (pair (nat %token_id) (map %token_info string bytes))) + (big_map %token_total_supply nat nat)))) + (big_map %metadata string bytes)) ; + code { PUSH string "FA2_TOKEN_UNDEFINED" ; + PUSH string "FA2_INSUFFICIENT_BALANCE" ; + LAMBDA + (pair (pair address nat) (big_map (pair address nat) nat)) + nat + { UNPAIR ; GET ; IF_NONE { PUSH nat 0 } {} } ; + DUP ; + LAMBDA + (pair (lambda (pair (pair address nat) (big_map (pair address nat) nat)) nat) + (pair (pair address nat) (pair nat (big_map (pair address nat) nat)))) + (big_map (pair address nat) nat) + { DUP ; + CDR ; + SWAP ; + CAR ; + SWAP ; + UNPAIR ; + UNPAIR ; + DIG 2 ; + UNPAIR ; + DIG 3 ; + DIG 3 ; + PAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + SWAP ; + DUP ; + DUG 2 ; + PAIR ; + DIG 4 ; + SWAP ; + EXEC ; + DIG 2 ; + ADD ; + PUSH nat 0 ; + SWAP ; + DUP ; + DUG 2 ; + COMPARE ; + EQ ; + IF { DROP ; NONE nat ; SWAP ; UPDATE } + { DIG 2 ; SWAP ; SOME ; DIG 2 ; UPDATE } } ; + SWAP ; + APPLY ; + DIG 2 ; + DUP ; + DUG 3 ; + DIG 2 ; + DUP ; + DUG 3 ; + PAIR ; + LAMBDA + (pair (pair (lambda (pair (pair address nat) (big_map (pair address nat) nat)) nat) string) + (pair (pair address nat) (pair nat (big_map (pair address nat) nat)))) + (big_map (pair address nat) nat) + { DUP ; + CDR ; + SWAP ; + CAR ; + DUP ; + CDR ; + SWAP ; + CAR ; + DIG 2 ; + UNPAIR ; + UNPAIR ; + DIG 2 ; + UNPAIR ; + DIG 3 ; + DIG 3 ; + PAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + SWAP ; + DUP ; + DUG 2 ; + PAIR ; + DIG 4 ; + SWAP ; + EXEC ; + DIG 2 ; + SWAP ; + SUB ; + ISNAT ; + IF_NONE + { DROP 2 ; FAILWITH } + { DIG 3 ; + DROP ; + PUSH nat 0 ; + SWAP ; + DUP ; + DUG 2 ; + COMPARE ; + EQ ; + IF { DROP ; NONE nat ; SWAP ; UPDATE } + { DIG 2 ; SWAP ; SOME ; DIG 2 ; UPDATE } } } ; + SWAP ; + APPLY ; + LAMBDA + (option (pair (pair address bool) (option address))) + (lambda (option string) unit) + { LAMBDA + (pair (option (pair (pair address bool) (option address))) (option string)) + unit + { DUP ; + CDR ; + SWAP ; + CAR ; + IF_NONE + { DROP ; UNIT } + { CAR ; + CAR ; + SENDER ; + COMPARE ; + NEQ ; + IF { IF_NONE + { PUSH string "NOT_AN_ADMIN" ; FAILWITH } + { PUSH string " " ; CONCAT ; PUSH string "NOT_AN_ADMIN" ; CONCAT ; FAILWITH } } + { DROP ; UNIT } } } ; + SWAP ; + APPLY } ; + DIG 6 ; + UNPAIR ; + IF_LEFT + { DIG 6 ; + DROP ; + IF_LEFT + { DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + CAR ; + SWAP ; + IF_LEFT + { IF_LEFT + { DROP ; + DIG 2 ; + DROP ; + IF_NONE + { PUSH string "NO_ADMIN_CAPABILITIES_CONFIGURED" ; FAILWITH } + { DUP ; + CDR ; + IF_NONE + { DROP ; PUSH string "NO_PENDING_ADMIN" ; FAILWITH } + { SENDER ; + COMPARE ; + EQ ; + IF { NONE address ; SWAP ; CAR ; CDR ; SENDER ; PAIR ; PAIR ; SOME } + { DROP ; PUSH string "NOT_A_PENDING_ADMIN" ; FAILWITH } } } ; + NIL operation ; + PAIR } + { SWAP ; + DUP ; + DUG 2 ; + DIG 4 ; + SWAP ; + EXEC ; + DROP ; + SWAP ; + IF_NONE + { DROP ; PUSH string "NO_ADMIN_CAPABILITIES_CONFIGURED" ; FAILWITH } + { DUP ; CDR ; DUG 2 ; CAR ; CAR ; PAIR ; PAIR ; SOME } ; + NIL operation ; + PAIR } } + { SWAP ; + DUP ; + DUG 2 ; + DIG 4 ; + SWAP ; + EXEC ; + DROP ; + SWAP ; + IF_NONE + { DROP ; PUSH string "NO_ADMIN_CAPABILITIES_CONFIGURED" ; FAILWITH } + { SWAP ; SOME ; SWAP ; CAR ; PAIR ; SOME } ; + NIL operation ; + PAIR } ; + UNPAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + DIG 3 ; + CAR ; + CDR ; + DIG 3 ; + PAIR ; + PAIR ; + SWAP ; + PAIR } + { DIG 2 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + CAR ; + IF_NONE + { UNIT } + { CAR ; CDR ; IF { PUSH string "PAUSED" ; FAILWITH } { UNIT } } ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + CDR ; + SWAP ; + IF_LEFT + { IF_LEFT + { DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + DIG 2 ; + DUP ; + DUG 3 ; + CAR ; + CAR ; + DIG 2 ; + DUP ; + CAR ; + MAP { DIG 3 ; + DUP ; + DUG 4 ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + MEM ; + NOT ; + IF { DROP ; DIG 6 ; DUP ; DUG 7 ; FAILWITH } + { DIG 2 ; + DUP ; + DUG 3 ; + SWAP ; + DUP ; + DUG 2 ; + PAIR ; + DIG 7 ; + DUP ; + DUG 8 ; + SWAP ; + EXEC ; + SWAP ; + PAIR } } ; + DIG 2 ; + DROP ; + DIG 2 ; + DROP ; + DIG 4 ; + DROP ; + DIG 4 ; + DROP ; + SWAP ; + CDR ; + PUSH mutez 0 ; + DIG 2 ; + TRANSFER_TOKENS ; + SWAP ; + NIL operation ; + DIG 2 ; + CONS ; + PAIR } + { DIG 5 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + LAMBDA + (pair (pair address address) (pair nat (big_map (pair address (pair address nat)) unit))) + unit + { UNPAIR ; + UNPAIR ; + DIG 2 ; + UNPAIR ; + DIG 3 ; + DUP ; + DUG 4 ; + DIG 3 ; + DUP ; + DUG 4 ; + COMPARE ; + EQ ; + IF { DROP 4 ; UNIT } + { DIG 3 ; + PAIR ; + DIG 2 ; + PAIR ; + MEM ; + IF { UNIT } { PUSH string "FA2_NOT_OPERATOR" ; FAILWITH } } } ; + DUG 2 ; + DUP ; + DUG 3 ; + CAR ; + CAR ; + SWAP ; + ITER { DUP ; + DUG 2 ; + CDR ; + ITER { SWAP ; + DIG 4 ; + DUP ; + DUG 5 ; + CDR ; + CAR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CAR ; + MEM ; + NOT ; + IF { DROP 2 ; DIG 7 ; DUP ; DUG 8 ; FAILWITH } + { DIG 4 ; + DUP ; + DUG 5 ; + CAR ; + CDR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CAR ; + PAIR ; + SENDER ; + DIG 4 ; + DUP ; + DUG 5 ; + CAR ; + PAIR ; + PAIR ; + DIG 4 ; + DUP ; + DUG 5 ; + SWAP ; + EXEC ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + DIG 3 ; + DUP ; + DUG 4 ; + CAR ; + PAIR ; + PAIR ; + DIG 7 ; + DUP ; + DUG 8 ; + SWAP ; + EXEC ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CDR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + DIG 2 ; + CAR ; + PAIR ; + PAIR ; + DIG 7 ; + DUP ; + DUG 8 ; + SWAP ; + EXEC } } ; + SWAP ; + DROP } ; + SWAP ; + DROP ; + SWAP ; + DROP ; + DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + DIG 2 ; + CAR ; + CDR ; + DIG 2 ; + PAIR ; + PAIR ; + NIL operation ; + PAIR } } + { DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + CDR ; + SWAP ; + SENDER ; + DUG 2 ; + ITER { SWAP ; + DIG 2 ; + DUP ; + DUG 3 ; + DIG 2 ; + DUP ; + DUG 3 ; + IF_LEFT {} {} ; + CAR ; + COMPARE ; + EQ ; + IF {} { PUSH string "FA2_NOT_OWNER" ; FAILWITH } ; + SWAP ; + IF_LEFT + { SWAP ; + UNIT ; + SOME ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CAR ; + PAIR ; + DIG 3 ; + CAR ; + PAIR ; + UPDATE } + { DUP ; + DUG 2 ; + CDR ; + CDR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CAR ; + PAIR ; + DIG 2 ; + CAR ; + PAIR ; + NONE unit ; + SWAP ; + UPDATE } } ; + SWAP ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + SWAP ; + DIG 2 ; + CAR ; + CAR ; + PAIR ; + PAIR ; + NIL operation ; + PAIR } ; + UNPAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + DIG 2 ; + DIG 3 ; + CAR ; + CAR ; + PAIR ; + PAIR ; + SWAP ; + PAIR } } + { DIG 5 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + CAR ; + DIG 3 ; + SWAP ; + EXEC ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + CDR ; + SWAP ; + IF_LEFT + { DIG 4 ; + DROP ; + IF_LEFT + { SWAP ; + DUP ; + DUG 2 ; + CAR ; + CAR ; + SWAP ; + DUP ; + DUG 2 ; + ITER { DUP ; + DUG 2 ; + CDR ; + CDR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + DIG 2 ; + CAR ; + PAIR ; + PAIR ; + DIG 4 ; + DUP ; + DUG 5 ; + SWAP ; + EXEC } ; + DIG 4 ; + DROP ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + DIG 2 ; + ITER { SWAP ; + DUP ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CAR ; + GET ; + IF_NONE + { DROP 2 ; DIG 4 ; DUP ; DUG 5 ; FAILWITH } + { DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + SWAP ; + SUB ; + ISNAT ; + IF_NONE { DIG 5 ; DUP ; DUG 6 ; FAILWITH } {} ; + SOME ; + DIG 2 ; + CDR ; + CAR ; + UPDATE } } ; + DIG 4 ; + DROP ; + DIG 4 ; + DROP ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + DIG 3 ; + CAR ; + CDR ; + DIG 3 ; + PAIR ; + PAIR ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + PAIR ; + SWAP ; + CAR ; + PAIR ; + NIL operation ; + PAIR } + { DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + DIG 3 ; + DROP ; + DUP ; + CAR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CAR ; + SWAP ; + DUP ; + DUG 2 ; + GET ; + IF_NONE + { DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + DIG 3 ; + DUP ; + DUG 4 ; + CDR ; + CAR ; + DIG 3 ; + DIG 3 ; + DUP ; + DUG 4 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + PAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + CAR ; + PAIR ; + DIG 2 ; + CDR ; + CDR ; + PUSH nat 0 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + PAIR ; + SWAP ; + CAR ; + PAIR } + { DROP 4 ; PUSH string "FA2_DUP_TOKEN_ID" ; FAILWITH } ; + NIL operation ; + PAIR } } + { DIG 3 ; + DROP ; + DIG 4 ; + DROP ; + SWAP ; + DUP ; + DUG 2 ; + CAR ; + CAR ; + SWAP ; + DUP ; + DUG 2 ; + ITER { DUP ; + DUG 2 ; + CDR ; + CDR ; + PAIR ; + SWAP ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + DIG 2 ; + CAR ; + PAIR ; + PAIR ; + DIG 4 ; + DUP ; + DUG 5 ; + SWAP ; + EXEC } ; + DIG 4 ; + DROP ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + DIG 2 ; + ITER { SWAP ; + DUP ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CAR ; + GET ; + IF_NONE + { DROP 2 ; DIG 3 ; DUP ; DUG 4 ; FAILWITH } + { DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + CDR ; + ADD ; + SOME ; + DIG 2 ; + CDR ; + CAR ; + UPDATE } } ; + DIG 4 ; + DROP ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + DIG 3 ; + CAR ; + CDR ; + DIG 3 ; + PAIR ; + PAIR ; + DUP ; + DUG 2 ; + CDR ; + CAR ; + PAIR ; + SWAP ; + CAR ; + PAIR ; + NIL operation ; + PAIR } ; + UNPAIR ; + DIG 2 ; + DUP ; + DUG 3 ; + CDR ; + DIG 2 ; + DIG 3 ; + CAR ; + CAR ; + PAIR ; + PAIR ; + SWAP ; + PAIR } } } + diff --git a/src/test-data/contracts/example-lambda.tz b/src/test-data/contracts/example-lambda.tz new file mode 100644 index 0000000..8b22e44 --- /dev/null +++ b/src/test-data/contracts/example-lambda.tz @@ -0,0 +1,29 @@ +{ parameter (or (unit %callModifyValue) (lambda %updateModifyValueFunction int int)) ; + storage (pair (int %currentValue) (lambda %modifyValue int int)) ; + code { UNPAIR ; + SWAP ; + UNPAIR ; + DIG 2 ; + IF_LEFT { DROP ; DUP 2 ; SWAP ; EXEC ; SWAP } { DIG 2 ; DROP } ; + SWAP ; + PAIR ; + NIL operation ; + PAIR } ; + view "getView" + string + int + { UNPAIR ; + PUSH string "checkFunction" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; DUP ; CAR ; SWAP ; CDR ; SWAP ; EXEC } + { SWAP ; + DROP ; + PUSH string " not found on this contract" ; + SWAP ; + PUSH string "View " ; + CONCAT ; + CONCAT ; + FAILWITH } } } + diff --git a/src/test-data/contracts/subdir/example-contract-0.tz b/src/test-data/contracts/subdir/example-contract-0.tz new file mode 100644 index 0000000..8f32093 --- /dev/null +++ b/src/test-data/contracts/subdir/example-contract-0.tz @@ -0,0 +1,7 @@ +{ parameter (or (or (int %decrement) (int %increment)) (unit %reset)) ; + storage int ; + code { UNPAIR ; + IF_LEFT { IF_LEFT { SWAP ; SUB } { ADD } } { DROP 2 ; PUSH int 0 } ; + NIL operation ; + PAIR } } + diff --git a/src/test-data/types-file/example-contract-1.types.ts b/src/test-data/types-file/example-contract-1.types.ts new file mode 100644 index 0000000..63e81d3 --- /dev/null +++ b/src/test-data/types-file/example-contract-1.types.ts @@ -0,0 +1,87 @@ + +import { ContractAbstractionFromContractType, WalletContractAbstractionFromContractType } from './type-utils'; +import { address, BigMap, int, mutez, nat, timestamp } from './type-aliases'; + +export type Storage = { + pauseable_admin?: { + admin: address; + paused: boolean; + pending_admin?: address; + }; + current_id: nat; + max_auction_time: nat; + max_config_to_start_time: nat; + auctions: BigMap; + }>; + min_raise_percent: nat; + min_raise: mutez; + end_time: timestamp; + highest_bidder: address; + }>; +}; + +type Methods = { + confirm_admin: () => Promise; + pause: (param: boolean) => Promise; + set_admin: (param: address) => Promise; + bid: (param: nat) => Promise; + cancel: (param: nat) => Promise; + configure: ( + opening_price: mutez, + min_raise_percent: nat, + min_raise: mutez, + round_time: nat, + extend_time: nat, + asset: Array<{ + fa2_address: address; + fa2_batch: Array<{ + token_id: nat; + amount: nat; + }>; + }>, + start_time: timestamp, + end_time: timestamp, + ) => Promise; + resolve: (param: nat) => Promise; +}; + +type MethodsObject = { + confirm_admin: () => Promise; + pause: (param: boolean) => Promise; + set_admin: (param: address) => Promise; + bid: (param: nat) => Promise; + cancel: (param: nat) => Promise; + configure: (params: { + opening_price: mutez, + min_raise_percent: nat, + min_raise: mutez, + round_time: nat, + extend_time: nat, + asset: Array<{ + fa2_address: address; + fa2_batch: Array<{ + token_id: nat; + amount: nat; + }>; + }>, + start_time: timestamp, + end_time: timestamp, + }) => Promise; + resolve: (param: nat) => Promise; +}; + +type contractTypes = { methods: Methods, methodsObject: MethodsObject, storage: Storage, code: { __type: 'ExampleContract1Code', protocol: string, code: object[] } }; +export type ExampleContract1ContractType = ContractAbstractionFromContractType; +export type ExampleContract1WalletType = WalletContractAbstractionFromContractType; diff --git a/src/test-data/types-file/example-contract-2.types.ts b/src/test-data/types-file/example-contract-2.types.ts new file mode 100644 index 0000000..b28f923 --- /dev/null +++ b/src/test-data/types-file/example-contract-2.types.ts @@ -0,0 +1,122 @@ + +import { ContractAbstractionFromContractType, WalletContractAbstractionFromContractType } from './type-utils'; +import { address, BigMap, bytes, contract, MMap, nat, unit } from './type-aliases'; + +export type Storage = { + admin?: { + admin: address; + paused: boolean; + pending_admin?: address; + }; + assets: { + ledger: BigMap<{ + 0: address; + 1: nat; + }, nat>; + operators: BigMap<{ + 0: address; + 1: address; + 2: nat; + }, unit>; + token_metadata: BigMap; + }>; + token_total_supply: BigMap; + }; + metadata: BigMap; +}; + +type Methods = { + confirm_admin: () => Promise; + pause: (param: boolean) => Promise; + set_admin: (param: address) => Promise; + balance_of: ( + requests: Array<{ + owner: address; + token_id: nat; + }>, + callback: contract, + ) => Promise; + transfer: (param: Array<{ + from_: address; + txs: Array<{ + to_: address; + token_id: nat; + amount: nat; + }>; + }>) => Promise; + add_operator: ( + owner: address, + operator: address, + token_id: nat, + ) => Promise; + remove_operator: ( + owner: address, + operator: address, + token_id: nat, + ) => Promise; + burn_tokens: (param: Array<{ + owner: address; + token_id: nat; + amount: nat; + }>) => Promise; + create_token: ( + token_id: nat, + token_info: MMap, + ) => Promise; + mint_tokens: (param: Array<{ + owner: address; + token_id: nat; + amount: nat; + }>) => Promise; +}; + +type MethodsObject = { + confirm_admin: () => Promise; + pause: (param: boolean) => Promise; + set_admin: (param: address) => Promise; + balance_of: (params: { + requests: Array<{ + owner: address; + token_id: nat; + }>, + callback: contract, + }) => Promise; + transfer: (param: Array<{ + from_: address; + txs: Array<{ + to_: address; + token_id: nat; + amount: nat; + }>; + }>) => Promise; + add_operator: (params: { + owner: address, + operator: address, + token_id: nat, + }) => Promise; + remove_operator: (params: { + owner: address, + operator: address, + token_id: nat, + }) => Promise; + burn_tokens: (param: Array<{ + owner: address; + token_id: nat; + amount: nat; + }>) => Promise; + create_token: (params: { + token_id: nat, + token_info: MMap, + }) => Promise; + mint_tokens: (param: Array<{ + owner: address; + token_id: nat; + amount: nat; + }>) => Promise; +}; + +type contractTypes = { methods: Methods, methodsObject: MethodsObject, storage: Storage, code: { __type: 'ExampleContract2Code', protocol: string, code: object[] } }; +export type ExampleContract2ContractType = ContractAbstractionFromContractType; +export type ExampleContract2WalletType = WalletContractAbstractionFromContractType; diff --git a/src/test-data/types-file/example-lambda.types.ts b/src/test-data/types-file/example-lambda.types.ts new file mode 100644 index 0000000..9dceb57 --- /dev/null +++ b/src/test-data/types-file/example-lambda.types.ts @@ -0,0 +1,22 @@ + +import { ContractAbstractionFromContractType, WalletContractAbstractionFromContractType } from './type-utils'; +import { Instruction, int } from './type-aliases'; + +export type Storage = { + currentValue: int; + modifyValue: Instruction[]; +}; + +type Methods = { + callModifyValue: () => Promise; + updateModifyValueFunction: (param: Instruction[]) => Promise; +}; + +type MethodsObject = { + callModifyValue: () => Promise; + updateModifyValueFunction: (param: Instruction[]) => Promise; +}; + +type contractTypes = { methods: Methods, methodsObject: MethodsObject, storage: Storage, code: { __type: 'ExampleLambdaCode', protocol: string, code: object[] } }; +export type ExampleLambdaContractType = ContractAbstractionFromContractType; +export type ExampleLambdaWalletType = WalletContractAbstractionFromContractType; diff --git a/src/test-data/types-file/subdir/example-contract-0.types.ts b/src/test-data/types-file/subdir/example-contract-0.types.ts new file mode 100644 index 0000000..5a1053e --- /dev/null +++ b/src/test-data/types-file/subdir/example-contract-0.types.ts @@ -0,0 +1,21 @@ + +import { ContractAbstractionFromContractType, WalletContractAbstractionFromContractType } from '../type-utils'; +import { int } from '../type-aliases'; + +export type Storage = int; + +type Methods = { + decrement: (param: int) => Promise; + increment: (param: int) => Promise; + reset: () => Promise; +}; + +type MethodsObject = { + decrement: (param: int) => Promise; + increment: (param: int) => Promise; + reset: () => Promise; +}; + +type contractTypes = { methods: Methods, methodsObject: MethodsObject, storage: Storage, code: { __type: 'SubdirExampleContract0Code', protocol: string, code: object[] } }; +export type SubdirExampleContract0ContractType = ContractAbstractionFromContractType; +export type SubdirExampleContract0WalletType = WalletContractAbstractionFromContractType; diff --git a/src/test-data/types-file/type-aliases.ts b/src/test-data/types-file/type-aliases.ts new file mode 100644 index 0000000..22e0e59 --- /dev/null +++ b/src/test-data/types-file/type-aliases.ts @@ -0,0 +1,96 @@ +import { assertMichelsonInstruction, Expr, MichelsonCode } from '@taquito/michel-codec'; +import { MichelsonMap } from '@taquito/taquito'; +import { BigNumber } from 'bignumber.js'; + +export type Instruction = MichelsonCode; + +export type unit = (true | undefined) & { __type: 'unit' }; + +export type address = string & { __type: 'address' }; +export type bytes = string & { __type: 'bytes' }; +export type contract = string & { __type: 'contract' }; +export type operation = string & { __type: 'operation' }; +export type key = string & { __type: 'key' }; +export type key_hash = string & { __type: 'key_hash' }; +export type signature = string & { __type: 'signature' }; +export type ticket = string & { __type: 'ticket' }; + +export type timestamp = string & { __type: 'timestamp' }; + +export type int = BigNumber & { __type: 'int' }; +export type nat = BigNumber & { __type: 'nat' }; + +export type mutez = BigNumber & { __type: 'mutez' }; +export type tez = BigNumber & { __type: 'tez' }; + +type MapKey = Array | object | string | boolean | number; +export type MMap = Omit, 'get'> & { get: (key: K) => V }; +export type BigMap = Omit, 'get'> & { get: (key: K) => Promise }; + +export type chest = string & { __type: 'chest' }; +export type chest_key = string & { __type: 'chest_key' }; + +const createStringTypeTas = () => { + return (value: string): T => value as T; +}; + +const createBigNumberTypeTas = () => { + return (value: number | BigNumber | string): T => new BigNumber(value) as T; +}; + +type asMapParamOf = K extends string ? { [key: string]: V } | Array<{ key: K; value: V }> + : K extends number ? { [key: number]: V } | Array<{ key: K; value: V }> + : Array<{ key: K; value: V }>; + +function asMap(value: asMapParamOf): MMap { + const m = new MichelsonMap(); + if (Array.isArray(value)) { + const vArray = value as Array<{ key: K; value: V }>; + vArray.forEach(x => m.set(x.key, x.value)); + } else { + const vObject = value as { [key: string]: V }; + Object.keys(vObject).forEach(key => m.set(key as unknown as K, vObject[key])); + } + return m as MMap; +} +const asBigMap = (value: asMapParamOf) => asMap(value) as unknown as BigMap; + +function add(a: T, b: T): T { + return a.plus(b) as T; +} +function subtract(a: T, b: T): T { + return a.minus(b) as T; +} + +function createLambdaTypeTas(expr: Expr): MichelsonCode { + assertMichelsonInstruction(expr); + return expr as MichelsonCode; +} + +/** tas: Tezos 'as' casting for strict types */ +export const tas = { + address: createStringTypeTas
(), + bytes: createStringTypeTas(), + contract: createStringTypeTas(), + chest: createStringTypeTas(), + chest_key: createStringTypeTas(), + timestamp: (value: string | Date): timestamp => new Date(value).toISOString() as timestamp, + + int: createBigNumberTypeTas(), + nat: createBigNumberTypeTas(), + mutez: createBigNumberTypeTas(), + tez: createBigNumberTypeTas(), + + map: asMap, + bigMap: asBigMap, + + // Operations + add, + subtract, + + lambda: createLambdaTypeTas, + + // To number + number: (value: string | BigNumber) => Number(value + ''), + unit: () => true as unit, +}; diff --git a/src/test-data/types-file/type-utils.ts b/src/test-data/types-file/type-utils.ts new file mode 100644 index 0000000..7b05548 --- /dev/null +++ b/src/test-data/types-file/type-utils.ts @@ -0,0 +1,36 @@ + +import { ContractAbstraction, ContractMethod, ContractMethodObject, ContractProvider, Wallet } from '@taquito/taquito'; + +type BaseContractType = { methods: unknown, methodsObject: unknown, storage: unknown }; + +type ContractMethodsOf = { +[M in keyof TContract['methods']]: +TContract['methods'][M] extends (...args: infer A) => unknown +? (...args: A) => ContractMethod +: never +}; +type ContractMethodsObjectsOf = { +[M in keyof TContract['methodsObject']]: +TContract['methodsObject'][M] extends (...args: infer A) => unknown +? (...args: A) => ContractMethodObject +: never +}; +type ContractStorageOf = TContract['storage']; + +export type ContractAbstractionFromContractType = + ContractAbstraction, + ContractMethodsObjectsOf, + {}, + {}, + ContractStorageOf + >; + +export type WalletContractAbstractionFromContractType = + ContractAbstraction, + ContractMethodsObjectsOf, + {}, + {}, + ContractStorageOf + >;