Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
siradji committed Jun 25, 2021
1 parent 4e45d05 commit 7b811b3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Masternode', () => {
})

it('should resignMasternode', async () => {
const ownerAddress = await client.wallet.getNewAddress()
const ownerAddress = await container.getNewAddress()
const masternodeId = await client.masternode.createMasternode(ownerAddress)

await container.generate(1)
Expand All @@ -39,13 +39,13 @@ describe('Masternode', () => {
})

it('should resignMasternode with utxos', async () => {
const ownerAddress = await client.wallet.getNewAddress()
const ownerAddress = await container.getNewAddress()
const masternodeId = await client.masternode.createMasternode(ownerAddress)
const { txid } = await container.fundAddress(ownerAddress, 10)

await container.generate(1)

const utxos = (await client.wallet.listUnspent())
const utxos = (await container.call('listunspent'))
.filter((utxo: any) => utxo.txid === txid)
.map((utxo: any) => {
return {
Expand All @@ -69,6 +69,28 @@ describe('Masternode', () => {
}
})

it('should resignMasternode with arbitrary utxos', async () => {
const ownerAddress = await container.getNewAddress()
const masternodeId = await client.masternode.createMasternode(ownerAddress)
const { txid, vout } = await container.fundAddress(ownerAddress, 10)

await container.generate(1)

const hex = await client.masternode.resignMasternode(masternodeId, [{ txid, vout }])
expect(typeof hex).toStrictEqual('string')
expect(hex.length).toStrictEqual(64)

await container.generate(1)

const resignedMasternode = Object.values(await client.masternode.listMasternodes()).filter(mn => mn.ownerAuthAddress === ownerAddress)

expect(resignedMasternode.length).toStrictEqual(1)
for (const masternode of resignedMasternode) {
expect(masternode.state).toStrictEqual(MasternodeState.PRE_RESIGNED)
expect(masternode.resignTx).toStrictEqual(hex)
}
})

it('should throw an error with invalid masternode id', async () => {
const invalidMasternodeId = 'b3efcc1bf6cb77c465d7f5686a55f967e73b1a048a3716fdbffa523e22b66frb'
const promise = client.masternode.resignMasternode(invalidMasternodeId)
Expand Down
4 changes: 2 additions & 2 deletions packages/jellyfish-api-core/src/category/masternode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ export class Masternode {
* Creates a transaction resigning a masternode.
*
* @param {string} masternodeId The masternode's id.
* @param {UTXO[]} [utxos] Array of specified utxos to spend.
* @param {UTXO[]} [utxos = []] Array of specified utxos to spend.
* @param {string} [utxos.txid] The transaction id.
* @param {number} [utxos.vout] The output number.
* @return {Promise<string>} Resignation Transaction.
*/
async resignMasternode (masternodeId: string, utxos?: UTXO[]): Promise<string> {
async resignMasternode (masternodeId: string, utxos: UTXO[] = []): Promise<string> {
return await this.client.call('resignmasternode', [masternodeId, utxos], 'number')
}
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/jellyfish/api/masternode.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Creates a transaction resigning a masternode.

```ts title="client.masternode.resignMasternode()"
interface masternode {
resignMasternode (masternodeId: string, utxos?: UTXO[]): Promise<string>
resignMasternode (masternodeId: string, utxos: UTXO[] = []): Promise<string>
}

interface UTXO {
Expand Down

0 comments on commit 7b811b3

Please sign in to comment.