Skip to content

Commit

Permalink
Resolve PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
marktanrj committed Dec 1, 2022
1 parent 444d86e commit 0574935
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,14 @@ describe('UpdateMasternode', () => {
const masternodeId = await jsonRpc.masternode.createMasternode(collateralAddress)
await container.generate(1)

{
const masternodes = await jsonRpc.masternode.listMasternodes()
expect(masternodes[masternodeId]).toStrictEqual(expect.objectContaining({
state: 'PRE_ENABLED',
ownerAuthAddress: collateralAddress
}))
}

const address = await container.getNewAddress('', 'bech32')
const addressDest: P2WPKH = P2WPKH.fromAddress(RegTest, address, P2WPKH)
const addressDestKeyHash = addressDest.pubKeyHash
Expand All @@ -850,16 +858,16 @@ describe('UpdateMasternode', () => {
await expect(promise).rejects.toThrow(`DeFiDRpcError: 'bad-txns-customtx, UpdateMasternodeTx: Masternode ${masternodeId} is not in 'ENABLED' state (code 16)', code: -26`)
}

await container.generate(20)

{
const masternodes = await jsonRpc.masternode.listMasternodes()
expect(masternodes[masternodeId]).toStrictEqual(expect.objectContaining({
state: 'PRE_ENABLED',
state: 'ENABLED',
ownerAuthAddress: collateralAddress
}))
}

await container.generate(20)

{
const updateMasternode: UpdateMasternode = {
nodeId: masternodeId,
Expand All @@ -880,8 +888,6 @@ describe('UpdateMasternode', () => {
expect(outs[0].scriptPubKey.hex).toStrictEqual(expectedRedeemScript)
}

await container.generate(20)

{
const masternodes = await jsonRpc.masternode.listMasternodes()
expect(masternodes[masternodeId]).toStrictEqual(expect.objectContaining({
Expand Down Expand Up @@ -944,27 +950,27 @@ describe('Update Masternode (Multi-containers)', () => {
})
await node[0].generate(1)

const masternodeOwnerAddress = await node[0].rpc.wallet.getNewAddress()
const masternodeId = await node[0].rpc.masternode.createMasternode(masternodeOwnerAddress)
const masternodeOwnerAddress0 = await node[0].rpc.wallet.getNewAddress()
const masternodeId0 = await node[0].rpc.masternode.createMasternode(masternodeOwnerAddress0)
await node[0].generate(100) // create masternode and wait for it to be enabled

const operatorAddress = await node[0].rpc.wallet.getNewAddress()
const operatorAddressDest: P2WPKH = P2WPKH.fromAddress(RegTest, operatorAddress, P2WPKH)
const operatorAddressDestKeyHash = operatorAddressDest.pubKeyHash
const operatorScript = await fromAddress(operatorAddress, 'regtest')?.script as Script
const operatorAddress0 = await node[0].rpc.wallet.getNewAddress()
const operatorAddressDest0: P2WPKH = P2WPKH.fromAddress(RegTest, operatorAddress0, P2WPKH)
const operatorAddressDestKeyHash0 = operatorAddressDest0.pubKeyHash
const operatorScript = await fromAddress(operatorAddress0, 'regtest')?.script as Script
await node[0].generate(4)
await tGroup.waitForSync() // container2 should know about the new masternode

const updateMasternode: UpdateMasternode = {
nodeId: masternodeId,
const updateMasternode0: UpdateMasternode = {
nodeId: masternodeId0,
updates: [
{
updateType: 0x02,
address: { addressType: 0x04, addressPubKeyHash: operatorAddressDestKeyHash }
address: { addressType: 0x04, addressPubKeyHash: operatorAddressDestKeyHash0 }
}
]
}
const txn: TransactionSegWit = await builderNode1.masternode.update(updateMasternode, operatorScript)
const txn: TransactionSegWit = await builderNode1.masternode.update(updateMasternode0, operatorScript)
const promise = sendTransaction(node[1].container, txn)

await expect(promise).rejects.toThrow(DeFiDRpcError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class TxnBuilderMasternode extends P2WPKHTxnBuilder {
*
* @param {UpdateMasternode} updateMasternode transaction to create
* @param {Script} changeScript to send unspent to after deducting the (converted + fees)
* @param {Array<{ vin: Vin, vout: Vout, prevout: Prevout }>} [customVinVout = []] for custom vin and vout when updating owner address
* @return {Promise<TransactionSegWit>}
*/
async update (
Expand Down

0 comments on commit 0574935

Please sign in to comment.