wowok
Version:
Wowok Blockchain TypeScript API
1 lines • 4.88 kB
JavaScript
import{toBase58}from'../../_deps/bcs/index.js';import{describe,expect,it}from'vitest';import{bcs}from'../../bcs/index.js';import{Commands,Transaction}from'../index.js';import{Inputs}from'../Inputs.js';it('can\x20construct\x20and\x20serialize\x20an\x20empty\x20tranaction',()=>{const a=new Transaction();expect(()=>a['serialize']())['not']['toThrow']();}),it('can\x20construct\x20a\x20receiving\x20transaction\x20argument',()=>{const a=new Transaction();a['object'](Inputs['ReceivingRef'](ref())),expect(()=>a['serialize']())['not']['toThrow']();}),it('receiving\x20transaction\x20argument\x20different\x20from\x20object\x20argument',()=>{const a=ref(),b=new Transaction();b['object'](Inputs['ReceivingRef'](a));const c=new Transaction();c['object'](Inputs['ObjectRef'](a)),expect(()=>b['serialize']())['not']['toThrow'](),expect(()=>c['serialize']())['not']['toThrow'](),expect(c['serialize']())['not']['toEqual'](b['serialize']());}),it('can\x20be\x20serialized\x20and\x20deserialized\x20to\x20the\x20same\x20values',()=>{const a=new Transaction();a['add'](Commands['SplitCoins'](a['gas'],[a['pure']['u64'](0x64)]));const b=a['serialize'](),c=Transaction['from'](b);expect(b)['toEqual'](c['serialize']());}),it('allows\x20transfer\x20with\x20the\x20result\x20of\x20split\x20Commands',()=>{const a=new Transaction(),b=a['add'](Commands['SplitCoins'](a['gas'],[a['pure']['u64'](0x64)]));a['add'](Commands['TransferObjects']([b],a['object']('0x2')));}),it('supports\x20nested\x20results\x20through\x20either\x20array\x20index\x20or\x20destructuring',()=>{const a=new Transaction(),b=a['add'](Commands['MoveCall']({'target':'0x2::game::register'})),[c,d]=b;expect(c)['toBe'](b[0x0]),expect(d)['toBe'](b[0x1]);}),describe('offline\x20build',()=>{it('builds\x20an\x20empty\x20transaction\x20offline\x20when\x20provided\x20sufficient\x20data',async()=>{const a=setup();await a['build']();}),it('supports\x20epoch\x20expiration',async()=>{const a=setup();a['setExpiration']({'Epoch':0x1}),await a['build']();}),it('builds\x20a\x20split\x20transaction',async()=>{const a=setup();a['add'](Commands['SplitCoins'](a['gas'],[a['pure']['u64'](0x64)])),await a['build']();}),it('breaks\x20reference\x20equality',()=>{const a=setup(),b=Transaction['from'](a);a['setGasBudget'](0x3e7),expect(b['blockData'])['not']['toEqual'](a['blockData']),expect(a['blockData'])['not']['toBe'](a['blockData']),expect(a['blockData']['gasConfig'])['not']['toBe'](a['blockData']['gasConfig']),expect(a['blockData']['transactions'])['not']['toBe'](a['blockData']['transactions']),expect(a['blockData']['inputs'])['not']['toBe'](a['blockData']['inputs']);}),it('can\x20determine\x20the\x20type\x20of\x20inputs\x20for\x20built-in\x20Commands',async()=>{const a=setup();a['splitCoins'](a['gas'],[0x64]),await a['build']();}),it('supports\x20pre-serialized\x20inputs\x20as\x20Uint8Array',async()=>{const a=setup(),b=bcs['U64']['serialize'](0x64n)['toBytes']();a['add'](Commands['SplitCoins'](a['gas'],[a['pure'](b)])),await a['build']();}),it('builds\x20a\x20more\x20complex\x20interaction',async()=>{const a=setup(),b=a['splitCoins'](a['gas'],[0x64]);a['add'](Commands['MergeCoins'](a['gas'],[b,a['object'](Inputs['ObjectRef'](ref()))])),a['add'](Commands['MoveCall']({'target':'0x2::devnet_nft::mint','typeArguments':[],'arguments':[a['pure']['string']('foo'),a['pure']['string']('bar'),a['pure']['string']('baz')]})),await a['build']();}),it('uses\x20a\x20receiving\x20argument',async()=>{const a=setup();a['object'](Inputs['ObjectRef'](ref()));const b=a['splitCoins'](a['gas'],[0x64]);a['add'](Commands['MergeCoins'](a['gas'],[b,a['object'](Inputs['ObjectRef'](ref()))])),a['add'](Commands['MoveCall']({'target':'0x2::devnet_nft::mint','typeArguments':[],'arguments':[a['object'](Inputs['ObjectRef'](ref())),a['object'](Inputs['ReceivingRef'](ref()))]}));const c=await a['build'](),d=Transaction['from'](c),e=await d['build']();expect(c)['toEqual'](e);}),it('builds\x20a\x20more\x20complex\x20interaction',async()=>{const a=setup(),b=a['splitCoins'](a['gas'],[0x64]);a['add'](Commands['MergeCoins'](a['gas'],[b,a['object'](Inputs['ObjectRef'](ref()))])),a['add'](Commands['MoveCall']({'target':'0x2::devnet_nft::mint','typeArguments':[],'arguments':[a['pure']['string']('foo'),a['pure']['string']('bar'),a['pure']['string']('baz')]}));const c=await a['build'](),d=Transaction['from'](c),e=await d['build']();expect(c)['toEqual'](e);});});function ref(){return{'objectId':(Math['random']()*0x186a0)['toFixed'](0x0)['padEnd'](0x40,'0'),'version':String((Math['random']()*0x2710)['toFixed'](0x0)),'digest':toBase58(new Uint8Array([0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x1,0x2]))};}function setup(){const a=new Transaction();return a['setSender']('0x2'),a['setGasPrice'](0x5),a['setGasBudget'](0x64),a['setGasPayment']([ref()]),a;}