Skip to content

Commit

Permalink
WIP -- DOES NOT WORK
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmgdr committed Mar 7, 2024
1 parent 96e29b9 commit 97e761c
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 11 deletions.
74 changes: 71 additions & 3 deletions packages/cli/src/commands/governance/propose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ testWithGanache('governance:propose cmd', (web3: Web3) => {
'--from',
accounts[0],
'--descriptionURL',
'https://dummyurl.com',
'https://example.com',
])

const proposal = await governance.getProposal(1)
Expand Down Expand Up @@ -219,7 +219,7 @@ testWithGanache('governance:propose cmd', (web3: Web3) => {
'--from',
accounts[0],
'--descriptionURL',
'https://dummyurl.com',
'https://example.com',
'--force',
'--noInfo',
])
Expand Down Expand Up @@ -262,7 +262,7 @@ testWithGanache('governance:propose cmd', (web3: Web3) => {
'--from',
accounts[0],
'--descriptionURL',
'https://dummyurl.com',
'https://example.com',
'--force',
'--noInfo',
])
Expand Down Expand Up @@ -357,4 +357,72 @@ testWithGanache('governance:propose cmd', (web3: Web3) => {
},
EXTRA_LONG_TIMEOUT_MS
)

const transactionsForContractsVerifiedOnCeloScan = [
{
contract: '0xFa3df877F98ac5ecd87456a7AcCaa948462412f0',
address: '0xFa3df877F98ac5ecd87456a7AcCaa948462412f0',
function: 'removeLiquidity(uint256,uint256[],uint256)',
args: ['10000000000000000000000000', ['0', '0'], 1674883684],
value: '0',
},
{
contract: '0x765de816845861e75a25fca122bb6898b8b1282a',
address: '0x765de816845861e75a25fca122bb6898b8b1282a',
function: 'approve(address,uint256)',
args: ['0x87647780180B8f55980C7D3fFeFe08a9B29e9aE1', '11000000000000000000000000'],
value: '0',
},
{
contract: '0x37f750B7cC259A2f741AF45294f6a16572CF5cAd',
address: '0x37f750B7cC259A2f741AF45294f6a16572CF5cAd',
function: 'approve(address,uint256)',
args: ['0x87647780180B8f55980C7D3fFeFe08a9B29e9aE1', '11000000000000'],
value: '0',
},
]

test('when proposal contains transactions for contracts not verified', async () => {
const transactionsForUnverifiedContracts = [
{
contract: '0x552b9AA0eEe500c60f09456e49FBc1096322714C',
address: '0x37f750B7cC259A2f741AF45294f6a16572CF5cAd',
function: 'approve(address,uint256)',
args: ['0xFa3df877F98ac5ecd87456a7AcCaa948462412f0', '10000000000000000000000000'],
value: '0',
},
]
const transactionsToBeSaved = JSON.stringify(transactionsForUnverifiedContracts)
fs.writeFileSync('transactions.json', transactionsToBeSaved, { flag: 'w' })
expect(
async () =>
await testLocally(Propose, [
'--jsonTransactions',
'transactions.json',
'--deposit',
'1000000000000000000',
'--from',
accounts[0],
'--descriptionURL',
'https://example.com',
])
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Couldn't build call for transaction: {"contract":"0x552b9AA0eEe500c60f09456e49FBc1096322714C","function":"approve(address,uint256)","args":["0xFa3df877F98ac5ecd87456a7AcCaa948462412f0","10000000000000000000000000"],"value":"0"}"`
)
})

test.only('succeeds when proposal contains transactions for contracts verified on celoScan', async () => {
const transactionsToBeSaved = JSON.stringify(transactionsForContractsVerifiedOnCeloScan)
fs.writeFileSync('transactions2.json', transactionsToBeSaved, { flag: 'w' })
await testLocally(Propose, [
'--jsonTransactions',
'transactions2.json',
'--deposit',
'1000000000000000000',
'--from',
accounts[0],
'--descriptionURL',
'https://example.com',
])
})
})
2 changes: 1 addition & 1 deletion packages/cli/src/commands/releasecelo/locked-gold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class LockedGold extends ReleaseGoldBaseCommand {
const releaseOwner = await this.releaseGoldWrapper.getReleaseOwner()
const lockedGold = await kit.contracts.getLockedGold()
kit.defaultAccount = isRevoked ? releaseOwner : beneficiary

console.log(`Using account ${kit.defaultAccount}`)
if (flags.action === 'lock') {
// Must verify contract is account before checking pending withdrawals
await checkBuilder.addCheck('Is not revoked', () => !isRevoked).runChecks()
Expand Down
1 change: 1 addition & 0 deletions packages/cli/transactions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"contract":"0x552b9AA0eEe500c60f09456e49FBc1096322714C","function":"approve(address,uint256)","args":["0xFa3df877F98ac5ecd87456a7AcCaa948462412f0","10000000000000000000000000"],"value":"0"}]
1 change: 1 addition & 0 deletions packages/cli/transactions2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"contract":"0xFa3df877F98ac5ecd87456a7AcCaa948462412f0","address":"0xFa3df877F98ac5ecd87456a7AcCaa948462412f0","function":"removeLiquidity(uint256,uint256[],uint256)","args":["10000000000000000000000000",["0","0"],1674883684],"value":"0"},{"contract":"0x765de816845861e75a25fca122bb6898b8b1282a","address":"0x765de816845861e75a25fca122bb6898b8b1282a","function":"approve(address,uint256)","args":["0x87647780180B8f55980C7D3fFeFe08a9B29e9aE1","11000000000000000000000000"],"value":"0"},{"contract":"0x37f750B7cC259A2f741AF45294f6a16572CF5cAd","address":"0x37f750B7cC259A2f741AF45294f6a16572CF5cAd","function":"approve(address,uint256)","args":["0x87647780180B8f55980C7D3fFeFe08a9B29e9aE1","11000000000000"],"value":"0"}]
1 change: 1 addition & 0 deletions packages/sdk/explorer/src/block-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export class BlockExplorer {
this.kit.web3.utils.toChecksumAddress(address)
)
const mapping = metadata?.toContractMapping()
console.error('mapping', mapping)
if (mapping) {
this.addressMapping.set(address, mapping)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/explorer/src/sourcify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ export async function fetchMetadata(
if (fullMatchMetadata !== null) {
return fullMatchMetadata
}

console.error('None found on full match, trying celoScan')
const fullMatchFromCeloScan = await queryCeloScan(connection, contract)
if (fullMatchFromCeloScan !== null) {
return fullMatchFromCeloScan
}

console.error('No full match found, trying partial match')
if (strict) {
return null
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/governance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"blockchain"
],
"scripts": {
"build": "tsc -b .",
"clean": "tsc -b . --clean",
"build": "yarn run --top-level tsc -b .",
"clean": "yarn run --top-level tsc -b . --clean",
"docs": "yarn run --top-level typedoc",
"test": "yarn run --top-level jest --runInBand --passWithNoTests",
"lint": "yarn run --top-level eslint -c .eslintrc.js ",
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/governance/src/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export class ProposalBuilder {
buildCallToExternalContract = async (
tx: ProposalTransactionJSON
): Promise<ProposalTransaction> => {
if (!tx.address || !isValidAddress(tx.address)) {
if (!tx.address || (!isValidAddress(tx.address) && !isValidAddress(tx.contract))) {
throw new Error(`${tx.contract} is not a core celo contract so address must be specified`)
}

Expand Down Expand Up @@ -443,13 +443,13 @@ export class ProposalBuilder {
console.log(tx.address + ' is a proxy, repointing to ' + tx.args[0])
this.externalCallProxyRepoint.set(tx.address || tx.contract, tx.args[0] as string)
}

console.error('Building transaction for', tx)
const strategies = [this.buildCallToCoreContract, this.buildCallToExternalContract]

for (const strategy of strategies) {
try {
return await strategy(tx)
} catch (e) {
console.error('HELP', e)
debug("Couldn't build transaction with strategy %s: %O", strategy.name, e)
}
}
Expand Down

0 comments on commit 97e761c

Please sign in to comment.