diff --git a/src/core/__tests__/___option.___test.ts b/src/core/__tests__/___option.___test.ts new file mode 100644 index 0000000..084773a --- /dev/null +++ b/src/core/__tests__/___option.___test.ts @@ -0,0 +1,625 @@ +// import { AptosAccount, AptosClient, BCS, TxnBuilderTypes } from 'aptos'; + +// describe('option type', () => { +// const account = new AptosAccount( +// Buffer.from( +// 'da00cd868b59c22a1cb3cbfcb4bf0f8c8829662c504019c729825483fb85f9b2', +// 'hex', +// ), +// ); + +// it('view function some value', async () => { +// const client = new AptosClient('https://fullnode.devnet.aptoslabs.com/v1'); +// const result = await client.view({ +// function: +// 'f1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option::test_option_view', +// arguments: [{ vec: ['50'] }], +// type_arguments: [], +// }); +// expect(result).toMatchInlineSnapshot(` +// [ +// "50", +// ] +// `); +// }, 60000); + +// it('view function none value', async () => { +// const client = new AptosClient('https://fullnode.devnet.aptoslabs.com/v1'); +// const result = await client.view({ +// function: +// 'f1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option::test_option_view', +// arguments: [{ vec: [] }], +// type_arguments: [], +// }); +// expect(result).toMatchInlineSnapshot(` +// [ +// "0", +// ] +// `); +// }, 60000); + +// it('entry function none value', async () => { +// const client = new AptosClient('https://fullnode.devnet.aptoslabs.com/v1'); + +// const payload = TxnBuilderTypes.EntryFunction.natural( +// 'f1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option', +// 'test_option_entry', +// [], +// [ +// (() => { +// const serializer = new BCS.Serializer(); +// serializer.serializeU32AsUleb128(0); +// return serializer.getBytes(); +// })(), +// ], +// ); + +// const entryFunctionPayload = +// new TxnBuilderTypes.TransactionPayloadEntryFunction(payload); +// const rawTxn = await client.generateRawTransaction( +// account.address(), +// entryFunctionPayload, +// ); +// const transactionRes = ( +// await client.simulateTransaction(account, rawTxn) +// )[0]; + +// expect(transactionRes).toMatchInlineSnapshot(` +// { +// "accumulator_root_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "changes": [ +// { +// "address": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "data": { +// "data": { +// "coin": { +// "value": "99999800", +// }, +// "deposit_events": { +// "counter": "1", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "2", +// }, +// }, +// }, +// "frozen": false, +// "withdraw_events": { +// "counter": "0", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "3", +// }, +// }, +// }, +// }, +// "type": "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>", +// }, +// "state_key_hash": "0xa556bae1fc4f288457c0edb53f3de4e5007d02a83d57cfb7a7cf68975ad67f39", +// "type": "write_resource", +// }, +// { +// "address": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "data": { +// "data": { +// "authentication_key": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "coin_register_events": { +// "counter": "1", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "0", +// }, +// }, +// }, +// "guid_creation_num": "4", +// "key_rotation_events": { +// "counter": "0", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "1", +// }, +// }, +// }, +// "rotation_capability_offer": { +// "for": { +// "vec": [], +// }, +// }, +// "sequence_number": "1", +// "signer_capability_offer": { +// "for": { +// "vec": [], +// }, +// }, +// }, +// "type": "0x1::account::Account", +// }, +// "state_key_hash": "0x431c478122ab13d3e724f1057607e66b0e9ebda9cdb3e805fc7d0e5a25d54908", +// "type": "write_resource", +// }, +// { +// "data": null, +// "handle": "0x1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca", +// "key": "0x0619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935", +// "state_key_hash": "0x6e4b28d40f98a106a65163530924c0dcb40c1349d3aa915d108b4d6cfc1ddb19", +// "type": "write_table_item", +// "value": "0xf8df61157eaf03000100000000000000", +// }, +// ], +// "event_root_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "events": [], +// "expiration_timestamp_secs": "1686842198", +// "gas_unit_price": "100", +// "gas_used": "2", +// "hash": "0x88199cef515f5f8676fe9707d871b0dee7d7c978c5d09e0d277f13cd490b48b2", +// "max_gas_amount": "200000", +// "payload": { +// "arguments": [ +// { +// "vec": [], +// }, +// ], +// "function": "0xf1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option::test_option_entry", +// "type": "entry_function_payload", +// "type_arguments": [], +// }, +// "sender": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "sequence_number": "0", +// "signature": { +// "public_key": "0x02ee6ce9095398182bf86a9cfdc68fbe4e14ebe169fa3d67075f4267a7b5cc6f", +// "signature": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", +// "type": "ed25519_signature", +// }, +// "state_change_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "state_checkpoint_hash": null, +// "success": false, +// "timestamp": "1686842178601766", +// "version": "104442985", +// "vm_status": "Move abort in 0xf1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option: 0x1", +// } +// `); +// }, 60000); + +// it('entry function some value', async () => { +// const client = new AptosClient('https://fullnode.devnet.aptoslabs.com/v1'); + +// const payload = TxnBuilderTypes.EntryFunction.natural( +// 'f1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option', +// 'test_option_entry', +// [], +// [ +// (() => { +// const serializer = new BCS.Serializer(); +// serializer.serializeU32AsUleb128(1); +// serializer.serializeU64(BigInt(1000)); +// return serializer.getBytes(); +// })(), +// ], +// ); + +// const entryFunctionPayload = +// new TxnBuilderTypes.TransactionPayloadEntryFunction(payload); +// const rawTxn = await client.generateRawTransaction( +// account.address(), +// entryFunctionPayload, +// ); +// const transactionRes = ( +// await client.simulateTransaction(account, rawTxn) +// )[0]; + +// expect(transactionRes).toMatchInlineSnapshot(` +// { +// "accumulator_root_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "changes": [ +// { +// "address": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "data": { +// "data": { +// "coin": { +// "value": "99999800", +// }, +// "deposit_events": { +// "counter": "1", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "2", +// }, +// }, +// }, +// "frozen": false, +// "withdraw_events": { +// "counter": "0", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "3", +// }, +// }, +// }, +// }, +// "type": "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>", +// }, +// "state_key_hash": "0xa556bae1fc4f288457c0edb53f3de4e5007d02a83d57cfb7a7cf68975ad67f39", +// "type": "write_resource", +// }, +// { +// "address": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "data": { +// "data": { +// "authentication_key": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "coin_register_events": { +// "counter": "1", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "0", +// }, +// }, +// }, +// "guid_creation_num": "4", +// "key_rotation_events": { +// "counter": "0", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "1", +// }, +// }, +// }, +// "rotation_capability_offer": { +// "for": { +// "vec": [], +// }, +// }, +// "sequence_number": "1", +// "signer_capability_offer": { +// "for": { +// "vec": [], +// }, +// }, +// }, +// "type": "0x1::account::Account", +// }, +// "state_key_hash": "0x431c478122ab13d3e724f1057607e66b0e9ebda9cdb3e805fc7d0e5a25d54908", +// "type": "write_resource", +// }, +// { +// "data": null, +// "handle": "0x1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca", +// "key": "0x0619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935", +// "state_key_hash": "0x6e4b28d40f98a106a65163530924c0dcb40c1349d3aa915d108b4d6cfc1ddb19", +// "type": "write_table_item", +// "value": "0xf8df61157eaf03000100000000000000", +// }, +// ], +// "event_root_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "events": [], +// "expiration_timestamp_secs": "1686842200", +// "gas_unit_price": "100", +// "gas_used": "2", +// "hash": "0x5e35c9a77869b2cd28ba1f7298ce881080649b77454f435a0d9a19283cac8ed9", +// "max_gas_amount": "200000", +// "payload": { +// "arguments": [ +// { +// "vec": [ +// "1000", +// ], +// }, +// ], +// "function": "0xf1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option::test_option_entry", +// "type": "entry_function_payload", +// "type_arguments": [], +// }, +// "sender": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "sequence_number": "0", +// "signature": { +// "public_key": "0x02ee6ce9095398182bf86a9cfdc68fbe4e14ebe169fa3d67075f4267a7b5cc6f", +// "signature": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", +// "type": "ed25519_signature", +// }, +// "state_change_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "state_checkpoint_hash": null, +// "success": true, +// "timestamp": "1686842178601766", +// "version": "104442985", +// "vm_status": "Executed successfully", +// } +// `); +// }, 60000); + +// it('entry function wrong value', async () => { +// const client = new AptosClient('https://fullnode.devnet.aptoslabs.com/v1'); + +// const payload = TxnBuilderTypes.EntryFunction.natural( +// 'f1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option', +// 'test_option_entry', +// [], +// [ +// (() => { +// const serializer = new BCS.Serializer(); +// serializer.serializeU32AsUleb128(1); +// serializer.serializeU128(BigInt(1000)); +// return serializer.getBytes(); +// })(), +// ], +// ); + +// const entryFunctionPayload = +// new TxnBuilderTypes.TransactionPayloadEntryFunction(payload); +// const rawTxn = await client.generateRawTransaction( +// account.address(), +// entryFunctionPayload, +// ); +// const transactionRes = ( +// await client.simulateTransaction(account, rawTxn) +// )[0]; + +// expect(transactionRes).toMatchInlineSnapshot(` +// { +// "accumulator_root_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "changes": [ +// { +// "address": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "data": { +// "data": { +// "coin": { +// "value": "99999800", +// }, +// "deposit_events": { +// "counter": "1", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "2", +// }, +// }, +// }, +// "frozen": false, +// "withdraw_events": { +// "counter": "0", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "3", +// }, +// }, +// }, +// }, +// "type": "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>", +// }, +// "state_key_hash": "0xa556bae1fc4f288457c0edb53f3de4e5007d02a83d57cfb7a7cf68975ad67f39", +// "type": "write_resource", +// }, +// { +// "address": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "data": { +// "data": { +// "authentication_key": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "coin_register_events": { +// "counter": "1", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "0", +// }, +// }, +// }, +// "guid_creation_num": "4", +// "key_rotation_events": { +// "counter": "0", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "1", +// }, +// }, +// }, +// "rotation_capability_offer": { +// "for": { +// "vec": [], +// }, +// }, +// "sequence_number": "1", +// "signer_capability_offer": { +// "for": { +// "vec": [], +// }, +// }, +// }, +// "type": "0x1::account::Account", +// }, +// "state_key_hash": "0x431c478122ab13d3e724f1057607e66b0e9ebda9cdb3e805fc7d0e5a25d54908", +// "type": "write_resource", +// }, +// { +// "data": null, +// "handle": "0x1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca", +// "key": "0x0619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935", +// "state_key_hash": "0x6e4b28d40f98a106a65163530924c0dcb40c1349d3aa915d108b4d6cfc1ddb19", +// "type": "write_table_item", +// "value": "0xf8df61157eaf03000100000000000000", +// }, +// ], +// "event_root_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "events": [], +// "expiration_timestamp_secs": "1686842202", +// "gas_unit_price": "100", +// "gas_used": "2", +// "hash": "0xbab7e07fd105787d094723f6fdc82fedb002c0ece7ba2659044cd1987e07ff72", +// "max_gas_amount": "200000", +// "payload": { +// "arguments": [ +// "0x01e8030000000000000000000000000000", +// ], +// "function": "0xf1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option::test_option_entry", +// "type": "entry_function_payload", +// "type_arguments": [], +// }, +// "sender": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "sequence_number": "0", +// "signature": { +// "public_key": "0x02ee6ce9095398182bf86a9cfdc68fbe4e14ebe169fa3d67075f4267a7b5cc6f", +// "signature": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", +// "type": "ed25519_signature", +// }, +// "state_change_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "state_checkpoint_hash": null, +// "success": false, +// "timestamp": "1686842178601766", +// "version": "104442985", +// "vm_status": "Transaction Executed and Committed with Error FAILED_TO_DESERIALIZE_ARGUMENT", +// } +// `); +// }, 60000); + +// it('entry function wrong value 2', async () => { +// const client = new AptosClient('https://fullnode.devnet.aptoslabs.com/v1'); + +// const payload = TxnBuilderTypes.EntryFunction.natural( +// 'f1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option', +// 'test_option_entry', +// [], +// [ +// (() => { +// const serializer = new BCS.Serializer(); +// serializer.serializeU64(BigInt(1000)); +// // serializer.serializeU64(BigInt(2000)); +// return serializer.getBytes(); +// })(), +// ], +// ); + +// const entryFunctionPayload = +// new TxnBuilderTypes.TransactionPayloadEntryFunction(payload); +// const rawTxn = await client.generateRawTransaction( +// account.address(), +// entryFunctionPayload, +// ); +// const transactionRes = ( +// await client.simulateTransaction(account, rawTxn) +// )[0]; + +// expect(transactionRes).toMatchInlineSnapshot(` +// { +// "accumulator_root_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "changes": [ +// { +// "address": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "data": { +// "data": { +// "coin": { +// "value": "99999800", +// }, +// "deposit_events": { +// "counter": "1", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "2", +// }, +// }, +// }, +// "frozen": false, +// "withdraw_events": { +// "counter": "0", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "3", +// }, +// }, +// }, +// }, +// "type": "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>", +// }, +// "state_key_hash": "0xa556bae1fc4f288457c0edb53f3de4e5007d02a83d57cfb7a7cf68975ad67f39", +// "type": "write_resource", +// }, +// { +// "address": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "data": { +// "data": { +// "authentication_key": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "coin_register_events": { +// "counter": "1", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "0", +// }, +// }, +// }, +// "guid_creation_num": "4", +// "key_rotation_events": { +// "counter": "0", +// "guid": { +// "id": { +// "addr": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "creation_num": "1", +// }, +// }, +// }, +// "rotation_capability_offer": { +// "for": { +// "vec": [], +// }, +// }, +// "sequence_number": "1", +// "signer_capability_offer": { +// "for": { +// "vec": [], +// }, +// }, +// }, +// "type": "0x1::account::Account", +// }, +// "state_key_hash": "0x431c478122ab13d3e724f1057607e66b0e9ebda9cdb3e805fc7d0e5a25d54908", +// "type": "write_resource", +// }, +// { +// "data": null, +// "handle": "0x1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca", +// "key": "0x0619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935", +// "state_key_hash": "0x6e4b28d40f98a106a65163530924c0dcb40c1349d3aa915d108b4d6cfc1ddb19", +// "type": "write_table_item", +// "value": "0xa819381280af03000100000000000000", +// }, +// ], +// "event_root_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "events": [], +// "expiration_timestamp_secs": "1686842465", +// "gas_unit_price": "100", +// "gas_used": "2", +// "hash": "0xc6e8cc795c059d6629f6075134dba8bcfbba76d6e5a83521fc6e07b68687b32b", +// "max_gas_amount": "200000", +// "payload": { +// "arguments": [ +// "0xe803000000000000", +// ], +// "function": "0xf1ab5cd814ef1480b8c36466310d9c21d7758b54f6121872d1fb43887a40e7d8::test_option::test_option_entry", +// "type": "entry_function_payload", +// "type_arguments": [], +// }, +// "sender": "0xc4f8e6cac35092bd4ca98b107b613d7ce0256deeacb147c8745589a493d4b36e", +// "sequence_number": "0", +// "signature": { +// "public_key": "0x02ee6ce9095398182bf86a9cfdc68fbe4e14ebe169fa3d67075f4267a7b5cc6f", +// "signature": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", +// "type": "ed25519_signature", +// }, +// "state_change_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", +// "state_checkpoint_hash": null, +// "success": false, +// "timestamp": "1686842445663505", +// "version": "104491153", +// "vm_status": "Transaction Executed and Committed with Error FAILED_TO_DESERIALIZE_ARGUMENT", +// } +// `); +// }, 60000); +// }); diff --git a/test_contract/sources/test_option.move b/test_contract/sources/test_option.move new file mode 100644 index 0000000..2a11481 --- /dev/null +++ b/test_contract/sources/test_option.move @@ -0,0 +1,14 @@ +module surf_addr::test_option { + use std::option::{Option, get_with_default, is_some}; + + #[view] + public fun test_option_view(t: Option): u64 { + get_with_default(&t, 0) + } + + public entry fun test_option_entry(t: Option) { + assert!(is_some(&t), 1); + get_with_default(&t, 0); + } +} + \ No newline at end of file