import { SUI_COIN } from '@msafe/sui3-utils'; import { TransactionBlock } from '@mysten/sui.js/transactions'; import { CONTRACT_ADDRESS } from '@/lib/config'; import { SUI_CLIENT } from '@/lib/globals'; import { RizeCore } from '@/lib/rize-core'; import { buildCoinTransferTxb } from '@/lib/transaction'; import { LocalWallet } from '@/lib/wallet'; const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000000000000000000000000000'; describe('receive balance', () => { const [wallet, otherWallet] = LocalWallet.getDefault(); const rizeCore = new RizeCore(SUI_CLIENT, CONTRACT_ADDRESS); rizeCore.connect(wallet); it('get owned objects of the rize object', async () => { const ownedBefore = await rizeCore.ownedCoins(); const sendSuiTxb = await buildCoinTransferTxb( SUI_CLIENT, { recipient: CONTRACT_ADDRESS.rizeV1ObjId, amount: '100', coinType: SUI_COIN, }, await wallet.address(), ); const res = await wallet.signAndSubmitTransaction(sendSuiTxb); expect(res.effects!.status.status).toBe('success'); const ownedAfter = await rizeCore.ownedCoins(); expect(ownedAfter.length).toBe(ownedBefore.length + 1); // Receive objects const res2 = await rizeCore.receiveCoins(ownedAfter); expect(res2.effects!.status.status).toBe('success'); const ownedLast = await rizeCore.ownedCoins(); expect(ownedLast.length).toBe(0); }); it('navi balance', async () => { const { supply, borrow } = await rizeCore.naviBalance(); expect(supply).toBe('0'); expect(borrow).toBe('0'); }); it('vault balance', async () => { const balance = await rizeCore.vaultBalance(SUI_COIN); expect(balance).not.toBe('0'); }); it('status check', async () => { const operator = await rizeCore.getOperator(); expect(operator).toBe(await wallet.address()); const ip = await rizeCore.isAdminTransferInProgress(); expect(ip).toBe(false); const { prevAdmin, newAdmin } = await rizeCore.getPendingTransfer(); expect(prevAdmin).toBe(ZERO_ADDRESS); expect(newAdmin).toBe(ZERO_ADDRESS); }); it('set operator', async () => { await rizeCore.setOperator(await otherWallet.address()); const newOperator = await rizeCore.getOperator(); expect(newOperator).toBe(await otherWallet.address()); await rizeCore.setOperator(await wallet.address()); expect(await rizeCore.getOperator()).toBe(await wallet.address()); }); it('transfer and reclaim admin', async () => { await rizeCore.initAdminTransfer(await otherWallet.address()); const ip1 = await rizeCore.isAdminTransferInProgress(); expect(ip1).toBe(true); const { prevAdmin, newAdmin } = await rizeCore.getPendingTransfer(); expect(prevAdmin).toBe(await wallet.address()); expect(newAdmin).toBe(await otherWallet.address()); // At this point, the original owner is not able to do admin expect(async () => rizeCore.setOperator(await otherWallet.address())).rejects.toThrow( 'The following input objects are invalid', ); await rizeCore.reclaimAdmin(); await rizeCore.setOperator(await wallet.address()); const ip2 = await rizeCore.isAdminTransferInProgress(); expect(ip2).toBe(false); const { prevAdmin: prev2, newAdmin: new2 } = await rizeCore.getPendingTransfer(); expect(prev2).toBe(ZERO_ADDRESS); expect(new2).toBe(ZERO_ADDRESS); }); it('transfer admin and accept, then transfer back', async () => { await rizeCore.initAdminTransfer(await otherWallet.address()); rizeCore.connect(otherWallet); await rizeCore.acceptAdmin(); await rizeCore.setOperator(await wallet.address()); const txb = new TransactionBlock(); txb.transferObjects([txb.object(CONTRACT_ADDRESS.adminCapObjId)], await wallet.address()); await otherWallet.signAndSubmitTransaction(txb); rizeCore.connect(wallet); await rizeCore.setOperator(await wallet.address()); }); });