Skip to content

Commit

Permalink
Explicitly listing the exising and proposed configuration to play aro…
Browse files Browse the repository at this point in the history
…und printDiff object comparison bug
  • Loading branch information
sdrug committed Mar 23, 2022
1 parent 78a330e commit 0b92e98
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,21 @@ export default class AcceptProposal extends SolanaCommand {
const proposalDigest = this.calculateProposalDigest(this.makeDigestInputFromProposal(proposalState as Proposal))
const isSameDigest = Buffer.compare(this.contractInput.offchainDigest, proposalDigest) === 0
this.require(isSameDigest, 'Digest generated is different from the onchain digest')

logger.success('Generated configuration matches with onchain proposal configuration')

logger.info(`Accepting config proposal at ${this.args[0]} with the following configuration`)
// final diff between proposal and actual contract state
diff.printDiff(contractConfig, proposalConfig)
await prompt('Continue?')
logger.info(`OffchainConfig difference in contract ${this.args[0]} and proposal ${this.input.proposalId}`)
diff.printDiff(
{ offchainConfig: contractConfig.offchainConfig, f: contractConfig.f },
{ offchainConfig: proposalConfig.offchainConfig, f: proposalConfig.f },
)

logger.info(`Existing Oracles Config on contract ${this.args[0]}`)
logger.log(contractConfig.oracles)
logger.info(`Proposed Oracles Config for contract ${this.args[0]}`)
logger.log(proposalConfig.oracles)

await prompt('Accept config proposal?')
}

execute = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ export default class ProposeConfig extends SolanaCommand {
}, {}),
}

logger.info(`Proposing new config on contract ${this.args[0]}:`)
diff.printDiff(contractConfig, proposedConfig)
logger.info(`Existing Config on contract ${this.args[0]}:`)
logger.log(contractConfig)
logger.info(`Proposed Config for contract ${this.args[0]}:`)
logger.log(proposedConfig)

// diff.printDiff(contractConfig, proposedConfig)
await prompt('Continue?')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export default class ProposeOffchainConfig extends SolanaCommand {
const proposedConfig = deserializeConfig(this.contractInput.serializedOffchainConfig)
const proposedConfigForDiff = prepareOffchainConfigForDiff(proposedConfig)

logger.info(`Proposed OffchainConfig for contract ${this.args[0]}`)
diff.printDiff(contractOffchainConfigForDiff, proposedConfigForDiff)

logger.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,40 +131,36 @@ export default class ProposePayees extends SolanaCommand {

beforeExecute = async () => {
const state = new PublicKey(this.args[0])
let contractState = await this.program.account.state.fetch(state)
let numOfOracles = contractState.oracles.len.toNumber()

if (numOfOracles === 0) {
// handle case when no oracles were set yet
// iterate through oracles list in proposal
const proposal = new PublicKey(this.input.proposalId)
contractState = await this.program.account.proposal.fetch(proposal)
}
const contractState = await this.program.account.state.fetch(state)

const payeesInContract = contractState.oracles.xs.slice(0, contractState.oracles.len.toNumber()).reduce(
(agg, { transmitter, payee }, idx) => ({
...agg,
[`operator#${idx}`]: {
[`oracle#${idx}`]: {
transmitter: transmitter.toString(),
payee: payee.toString(),
},
}),
{},
)
logger.info(`Existing payees on contract ${this.args[0]}`)
logger.log(payeesInContract)

const proposedPayees = Object.entries(payeesInContract).reduce(
(agg, [key, value]) => ({
const proposedPayees = Object.entries(this.contractInput.payeeByTransmitter).reduce(
(agg, [transmitter, payee], idx) => ({
...agg,
[key]: {
transmitter: (value as any).transmitter,
payee: this.contractInput.payeeByTransmitter[(value as any).transmitter].toString(),
[`oracle#${idx}`]: {
transmitter,
payee: payee.toString(),
},
}),
{},
)
logger.info(`Proposed payees for contract ${this.args[0]}`)
logger.log(proposedPayees)

logger.info(`Proposing payees for contract ${this.args[0]}`)
diff.printDiff(payeesInContract, proposedPayees)
// todo: enable diff when fixed
// diff.printDiff(payeesInContract, proposedPayees)
await prompt('Continue?')
}

Expand Down

0 comments on commit 0b92e98

Please sign in to comment.