Created
November 9, 2020 15:20
-
-
Save zviadm/52cc71fad7d7ad551e15d69806bac61e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ContractKit, newKit } from "@celo/contractkit"; | |
function increaseTime(kit: ContractKit, addSeconds: number) { | |
console.log(`time shift`, addSeconds) | |
const provider = kit.web3.currentProvider | |
if (!provider || typeof provider === "string") { | |
throw new Error(`invalid currentProvider!`) | |
} | |
return new Promise((resolve, reject) => { | |
provider.send({ | |
jsonrpc: '2.0', | |
id: Date.now(), | |
method: 'evm_increaseTime', | |
params: [addSeconds], | |
}, (err1) => { | |
if (err1) return reject(err1); | |
provider.send({ | |
jsonrpc: '2.0', | |
id: Date.now(), | |
method: 'evm_mine', | |
params: [], | |
}, (err2, res) => (err2 ? reject(err2) : resolve(res))); | |
}); | |
}); | |
} | |
async function main() { | |
const kit = await newKit("http://localhost:8545") | |
const lockedGold = await kit.contracts.getLockedGold() | |
const a0 = "0x5409ED021D9299bf6814279A6A1411A7e866A631" | |
kit.defaultAccount = a0 | |
const accounts = await kit.contracts.getAccounts() | |
console.log(`create account`) | |
if (!await accounts.isAccount(a0)) { | |
const tx = await accounts.createAccount() | |
await tx.sendAndWaitForReceipt() | |
} | |
const amt = 10e18.toFixed(0) | |
let tx = lockedGold.lock() | |
await tx.sendAndWaitForReceipt({value: amt} as any) | |
console.log(`unlock gold`) | |
tx = await lockedGold.unlock(amt) | |
await tx.sendAndWaitForReceipt({from: a0} as any) | |
await increaseTime(kit, 3*24*3600+1) | |
console.log(`withdraw`) | |
tx = await lockedGold.withdraw(0) | |
await tx.sendAndWaitForReceipt() | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment