Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('Authentic Submission Happy Path - SubmitBlock()', async () => {
const ion = await Ion.new(DEPLOYEDCHAINID);
const validation = await Validation.new(ion.address);
await validation.RegisterChain(TESTCHAINID, VALIDATORS, GENESIS_HASH);
// Fetch block 1 from testrpc
const block = web3.eth.getBlock(1);
const rlpHeaders = encoder.encodeBlockHeader(block);
const signedHeaderHash = Web3Utils.sha3(rlpHeaders.signed);
assert.equal(block.hash, signedHeaderHash);
// Submit block should succeed
const validationReceipt = await validation.SubmitBlock(TESTCHAINID, rlpHeaders.unsigned, rlpHeaders.signed);
const recoveredBlockHash = await validation.getLatestBlockHash.call(TESTCHAINID);
assert.equal(signedHeaderHash, recoveredBlockHash);
console.log("\tGas used to submit block = " + validationReceipt.receipt.gasUsed.toString() + " gas");
let blockHash = await validation.m_blockhashes(TESTCHAINID, block.hash);
assert.equal(blockHash, true);
let header = await validation.m_blockheaders(TESTCHAINID, block.hash);
// Separate fetched header info
parentHash = header[2];
const colony2 = await IColony.at(colonyAddress);
await colony2.setRewardInverse(100);
const tokenSupplyCeiling = toBN(2)
.pow(toBN(256))
.subn(1)
.toString();
await colony1.setTokenSupplyCeiling(tokenSupplyCeiling);
await colony2.setTokenSupplyCeiling(tokenSupplyCeiling);
// Giving both colonies the capability to call `mint` function
const adminRole = 1;
const newRoles = await DSRoles.new();
await newRoles.setUserRole(colony1.address, adminRole, true);
await newRoles.setUserRole(colony2.address, adminRole, true);
await newRoles.setRoleCapability(adminRole, newToken.address, sha3("mint(uint256)").slice(0, 10), true);
await newToken.setAuthority(newRoles.address);
await fundColonyWithTokens(colony1, otherToken, initialFunding.toString());
await fundColonyWithTokens(colony2, otherToken, initialFunding.toString());
// Minting the tokens so we can give them to users
await colony1.mintTokens(userReputation.toString());
await colony2.mintTokens(userReputation.toString());
// Giving the user colony's native tokens and reputation so they can participate in reward payout
await colony1.bootstrapColony([userAddress1], [userReputation.toString()]);
await colony2.bootstrapColony([userAddress1], [userReputation.toString()]);
// Submit current hash in active reputation mining cycle
await miningClient.addLogContentsToReputationTree();
await forwardTime(MINING_CYCLE_DURATION, this);
const expireB = expireHex(60) // need to add some proper time to here
const tokenA = token.address
const tokenB = token.address
const amountA = '0x' + web3Utils.toHex(100).slice(2).padStart(64,'0')
const amountB = '0x' + web3Utils.toHex(100).slice(2).padStart(64,'0')
const addrA = accounts[0]
const addrB = accounts[1]
const stateA = generateState(expireA, tokenA, amountA)
const stateB = generateState(expireB, tokenB, amountB)
const hashA = web3Utils.sha3(joinHex([fluorideAddrA,stateA]))
const hashB = web3Utils.sha3(joinHex([fluorideAddrB,stateB]))
const sigA = web3.eth.sign(addrA,hashA)
const hashAB = web3Utils.sha3(joinHex([hashA,addrA,hashB]))
const sigB = web3.eth.sign(addrB,hashAB)
const hashABC = web3Utils.sha3(joinHex([hashAB,addrB]))
const sigC = web3.eth.sign(addrA,hashABC)
assert.equal(hashABC,web3Utils.soliditySha3(hashAB,addrB),'hashing badly when compared with solidity')
// the two start functions should be done on different chains?
const receiptStartOnAbyA = await fluoride.Start_OnAbyA(
fluorideAddrA, expireA, tokenA, amountA, sigA,
fluorideAddrB, stateB, sigB, sigC)
it('should release transfered username', async () => {
let registrant = accountsArr[7];
await TestToken.methods.mint(registry.price).send({from: registrant});
await TestToken.methods.approve(UsernameRegistrar.address, registry.price).send({from: registrant});
let username = 'grace';
let usernameHash = namehash.hash(username + '.' + registry.registry);
let label = web3Utils.sha3(username);
let newOwner = accountsArr[8];
await UsernameRegistrar.methods.register(
label,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
await ENSRegistry.methods.setOwner(usernameHash, newOwner).send({from: registrant});
let releaseDelay = await UsernameRegistrar.methods.releaseDelay().call();
await utils.increaseTime(releaseDelay)
await utils.increaseTime(1000)
let initialAccountBalance = await UsernameRegistrar.methods.getAccountBalance(label).call();
let initialRegistrantBalance = await TestToken.methods.balanceOf(newOwner).call();
let initialRegistryBalance = await TestToken.methods.balanceOf(UsernameRegistrar.address).call();
await utils.increaseTime(1000)
let resultRelease = await UsernameRegistrar.methods.release(
const label = web3Utils.sha3(username);
await UsernameRegistrar.methods.register(
label,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
const releaseDelay = await UsernameRegistrar.methods.releaseDelay().call();
await utils.increaseTime(releaseDelay)
await utils.increaseTime(1000)
const initialAccountBalance = await UsernameRegistrar.methods.getAccountBalance(label).call();
const initialRegistrantBalance = await TestToken.methods.balanceOf(registrant).call();
const initialRegistryBalance = await TestToken.methods.balanceOf(UsernameRegistrar.address).call();
await utils.increaseTime(1000)
const resultRelease = await UsernameRegistrar.methods.release(
web3Utils.sha3(username),
).send({from: registrant});
//TODO: check events
assert.equal(await UsernameRegistrar.methods.getAccountBalance(label).call(), 0, "Final balance didnt zeroed");
assert.equal(await TestToken.methods.balanceOf(registrant).call(), (+initialRegistrantBalance)+(+initialAccountBalance), "Releaser token balance didnt increase")
assert.equal(await TestToken.methods.balanceOf(UsernameRegistrar.address).call(), (+initialRegistryBalance)-(+initialAccountBalance), "Registry token balance didnt decrease")
});
it('should release transfered username', async () => {
it('should register free pubkey only resolver-defined subdomain', async () => {
let subdomain = 'carlos';
let registrant = accountsArr[3];
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let pubkey = [web3Utils.sha3("0"), web3Utils.sha3("1")];
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
pubkey[0],
pubkey[1]
).send({from: registrant});
//TODO: check events
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, registrant, "Owner not set");
result = await ens.methods.resolver(usernameHash).call()
assert.equal(result, PublicResolver.address, "PublicResolver not set");
result = await PublicResolver.methods.addr(usernameHash).call()
assert.equal(result, utils.zeroAddress, "Resolved address unexpectedlly set");
result = await PublicResolver.methods.pubkey(usernameHash).call()
assert.equal(result[0], pubkey[0], "Resolved pubkey[0] not set");
it('should register free full resolver-defined subdomain', async () => {
let registrant = accountsArr[4];
let subdomain = 'david';
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
let pubkey = [web3Utils.sha3("2"), web3Utils.sha3("3")];
let result = await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
registrant,
pubkey[0],
pubkey[1]
).send({from: registrant});
//TODO: check events
result = await ens.methods.owner(usernameHash).call()
assert.equal(result, registrant, "Owner not set");
result = await ens.methods.resolver(usernameHash).call()
assert.equal(result, PublicResolver.address, "PublicResolver not set");
result = await PublicResolver.methods.addr(usernameHash).call()
function padKeccak256(data) {
return padLeft(sha3(data).slice(2), 64);
}
async function setupReverseRegistrar(ens, resolver, reverseRegistrar, accounts) {
await ens.setSubnodeOwner("0x0000000000000000000000000000000000000000", utils.sha3("reverse"), accounts[0]);
await ens.setSubnodeOwner(namehash.hash("reverse"), utils.sha3("addr"), reverseRegistrar.address);
}