Skip to content

Instantly share code, notes, and snippets.

@pnowosie
Created November 24, 2022 11:30
Show Gist options
  • Select an option

  • Save pnowosie/b5b32a6bb5acf537e27d46abcc343200 to your computer and use it in GitHub Desktop.

Select an option

Save pnowosie/b5b32a6bb5acf537e27d46abcc343200 to your computer and use it in GitHub Desktop.
Camino rewards collection test script for truffle
// Run: `truffle exec do_test.js`
const { toBN } = require("web3-utils/src/utils");
const BHAddr = '0x0100000000000000000000000000000000000000';
const IPAddr = '0x010000000000000000000000000000000000000c';
const toAddr = '0xa2AA6EbD9029F2c1498bD6ee1d1F6708Fd2A1e0b'
const buf = Buffer.alloc(32, 0);
// Slot 1
buf[0] = 1
const Slot1 = '0x'+buf.toString('hex')
// Slot 2
buf[0] = 2
const Slot2 = '0x'+buf.toString('hex')
module.exports = async (callback) => {
let accounts = await web3.eth.getAccounts()
const fromAddr = accounts[0];
////////////////////////////////////////////////
// Initial state
////////////////////////////////////////////////
var balance = await web3.eth.getBalance(fromAddr);
console.log(`Initial balance for the ${fromAddr} account: ${balance}`);
var balance = await web3.eth.getBalance(toAddr);
console.log(`Initial balance for the ${toAddr} account: ${balance}`);
var bhBalance = await web3.eth.getBalance(BHAddr);
var ipBalance = await web3.eth.getBalance(IPAddr);
console.log(`Initial balances BH (${bhBalance}) & IP (${ipBalance})`)
var slot1Val = toBN(await web3.eth.getStorageAt(BHAddr, Slot1)).toString();
var slot2Val = toBN(await web3.eth.getStorageAt(BHAddr, Slot2)).toString();
console.log(`Values stored at 1: (${slot1Val}) & 2: (${slot2Val})`);
////////////////////////////////////////////////
// Sending the Txs
////////////////////////////////////////////////
var blkno = await web3.eth.getBlockNumber()
console.log(`Chain height at ${blkno}`)
var tx = await web3.eth.sendTransaction({
from: accounts[0],
to: toAddr,
value: web3.utils.toWei("10")
})
console.log("Transfer of 1 CAM & Waiting...")
await new Promise(resolve => setTimeout(resolve, 2000));
var blkno = await web3.eth.getBlockNumber()
console.log(`Chain height at ${blkno}`)
var bhBalance = await web3.eth.getBalance(BHAddr);
var ipBalance = await web3.eth.getBalance(IPAddr);
console.log(`Initial balances BH (${bhBalance}) & IP (${ipBalance})`)
var slot1Val = toBN(await web3.eth.getStorageAt(BHAddr, Slot1)).toString();
var slot2Val = toBN(await web3.eth.getStorageAt(BHAddr, Slot2)).toString();
console.log(`Values stored at 1: (${slot1Val}) & 2: (${slot2Val})`);
callback();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment