Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const Address = require('@dashevo/dashcore-lib/lib/address');
const Script = require('@dashevo/dashcore-lib/lib/script');
const { KeyType, Identifier } = require('@dashevo/wasm-dpp');
const createOperatorIdentifier = require('./createOperatorIdentifier');
const createVotingIdentifier = require('./createVotingIdentifier');

/**
*
Expand Down Expand Up @@ -97,22 +96,23 @@ function handleNewMasternodeFactory(
}
}

const votingPubKeyHash = Buffer.from(proRegTxPayload.keyIDVoting, 'hex').reverse();
// const votingPubKeyHash = Buffer.from(proRegTxPayload.keyIDVoting, 'hex').reverse();

// TODO: Disabled until we have uniq keys support in DPP
// don't need to create a separate Identity in case we don't have
// voting public key (keyIDVoting === keyIDOwner)
if (!votingPubKeyHash.equals(ownerPublicKeyHash)) {
const votingIdentifier = createVotingIdentifier(masternodeEntry);

createdEntities.push(
await createMasternodeIdentity(
blockInfo,
votingIdentifier,
votingPubKeyHash,
KeyType.ECDSA_HASH160,
),
);
}
// if (!votingPubKeyHash.equals(ownerPublicKeyHash)) {
// const votingIdentifier = createVotingIdentifier(masternodeEntry);
//
// createdEntities.push(
// await createMasternodeIdentity(
// blockInfo,
// votingIdentifier,
// votingPubKeyHash,
// KeyType.ECDSA_HASH160,
// ),
// );
// }

return {
createdEntities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,19 @@ function synchronizeMasternodeIdentitiesFactory(
result = mergeEntities(result, affectedEntities);
}

const previousVotingMnEntry = previousMNList.find((previousMnListEntry) => (
previousMnListEntry.proRegTxHash === mnEntry.proRegTxHash
&& previousMnListEntry.votingAddress !== mnEntry.votingAddress
));

if (previousVotingMnEntry) {
const affectedEntities = await handleUpdatedVotingAddress(
mnEntry,
blockInfo,
);

result = mergeEntities(result, affectedEntities);
}
// const previousVotingMnEntry = previousMNList.find((previousMnListEntry) => (
// previousMnListEntry.proRegTxHash === mnEntry.proRegTxHash
// && previousMnListEntry.votingAddress !== mnEntry.votingAddress
// ));
//
// if (previousVotingMnEntry) {
// const affectedEntities = await handleUpdatedVotingAddress(
// mnEntry,
// blockInfo,
// );
//
// result = mergeEntities(result, affectedEntities);
// }

if (mnEntry.payoutAddress) {
const mnEntryWithChangedPayoutAddress = previousMNList.find((previousMnListEntry) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const handleNewMasternodeFactory = require('../../../../lib/identity/masternode/
const getSmlFixture = require('../../../../lib/test/fixtures/getSmlFixture');
const createOperatorIdentifier = require('../../../../lib/identity/masternode/createOperatorIdentifier');
const BlockInfo = require('../../../../lib/blockExecution/BlockInfo');
const createVotingIdentifier = require('../../../../lib/identity/masternode/createVotingIdentifier');

describe('handleNewMasternodeFactory', () => {
let handleNewMasternode;
Expand Down Expand Up @@ -65,12 +64,12 @@ describe('handleNewMasternodeFactory', () => {

const result = await handleNewMasternode(masternodeEntry, dataContract, blockInfo);

expect(result.createdEntities).to.have.lengthOf(2);
expect(result.createdEntities).to.have.lengthOf(1); // TODO: should be 2
expect(result.updatedEntities).to.have.lengthOf(0);
expect(result.removedEntities).to.have.lengthOf(0);

expect(result.createdEntities[0].toObject()).to.deep.equal(identityFixture.toObject());
expect(result.createdEntities[1].toObject()).to.deep.equal(identityFixture.toObject());
// expect(result.createdEntities[1].toObject()).to.deep.equal(identityFixture.toObject());

expect(fetchTransactionMock).to.be.calledOnceWithExactly(masternodeEntry.proRegTxHash);
expect(createMasternodeIdentityMock.getCall(0)).to.be.calledWithExactly(
Expand All @@ -81,12 +80,12 @@ describe('handleNewMasternodeFactory', () => {
payoutScript,
);

expect(createMasternodeIdentityMock.getCall(1)).to.be.calledWithExactly(
blockInfo,
Identifier.from('GVYoKVDd29gbmHzbVGepFjCbdymCS5Jq26CCiLnWNL6C'),
Buffer.from('6262626262626262626262626262626262626262', 'hex'),
KeyType.ECDSA_HASH160,
);
// expect(createMasternodeIdentityMock.getCall(1)).to.be.calledWithExactly(
// blockInfo,
// Identifier.from('GVYoKVDd29gbmHzbVGepFjCbdymCS5Jq26CCiLnWNL6C'),
// Buffer.from('6262626262626262626262626262626262626262', 'hex'),
// KeyType.ECDSA_HASH160,
// );

expect(createRewardShareDocumentMock).to.not.be.called();
});
Expand Down Expand Up @@ -126,24 +125,24 @@ describe('handleNewMasternodeFactory', () => {

const result = await handleNewMasternode(masternodeEntry, dataContract, blockInfo);

expect(result.createdEntities).to.have.lengthOf(3);
expect(result.createdEntities).to.have.lengthOf(2); // TODO: Should be 3
expect(result.updatedEntities).to.have.lengthOf(0);
expect(result.removedEntities).to.have.lengthOf(0);

expect(result.createdEntities[0].toJSON()).to.deep.equal(identityFixture.toJSON());
expect(result.createdEntities[1].toJSON()).to.deep.equal(identityFixture.toJSON());
expect(result.createdEntities[2].toJSON()).to.deep.equal(identityFixture.toJSON());
// expect(result.createdEntities[2].toJSON()).to.deep.equal(identityFixture.toJSON());

const operatorIdentifier = createOperatorIdentifier(masternodeEntry);
const operatorPayoutAddress = Address.fromString(masternodeEntry.operatorPayoutAddress);
const operatorPayoutScript = new Script(operatorPayoutAddress);

const votingIdentifier = createVotingIdentifier(masternodeEntry);
// const votingIdentifier = createVotingIdentifier(masternodeEntry);
const payoutAddress = Address.fromString(masternodeEntry.payoutAddress);
const payoutScript = new Script(payoutAddress);

expect(fetchTransactionMock).to.be.calledOnceWithExactly(masternodeEntry.proRegTxHash);
expect(createMasternodeIdentityMock).to.be.calledThrice();
expect(createMasternodeIdentityMock).to.be.calledTwice(); // TODO: Should be calledThrice
expect(createMasternodeIdentityMock.getCall(0)).to.be.calledWithExactly(
blockInfo,
Identifier.from('HYyu6DdUQyiHZwzeWpmahu7AUrsEF9MKkRcrdQnKeNSj'),
Expand All @@ -160,12 +159,12 @@ describe('handleNewMasternodeFactory', () => {
operatorPayoutScript,
);

expect(createMasternodeIdentityMock.getCall(2)).to.be.calledWithExactly(
blockInfo,
votingIdentifier,
Buffer.from('6262626262626262626262626262626262626262', 'hex'),
KeyType.ECDSA_HASH160,
);
// expect(createMasternodeIdentityMock.getCall(2)).to.be.calledWithExactly(
// blockInfo,
// votingIdentifier,
// Buffer.from('6262626262626262626262626262626262626262', 'hex'),
// KeyType.ECDSA_HASH160,
// );

expect(createRewardShareDocumentMock).to.be.calledOnceWithExactly(
dataContract,
Expand Down