Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("returns correct negative value", function() {
let bytes = [0xf5, 0xe2, 0xc5, 0x17]; // starts with 0b1
let raw = new BN("f5e2c517", 16);
let bitfipped = new BN(
raw.toString(2)
.replace(/0/g, "x")
.replace(/1/g, "0")
.replace(/x/g, "1"),
2
);
let expectedValue = bitfipped.add(new BN(1)).neg();
let result = utils.toSignedBN(bytes);
assert.equal(result.toString(), expectedValue.toString());
});
const block = await data.contract.interfaceAdapter.getBlock(
data.receipt.includedInBlock
);
// if geth returns null, try again!
if (!block) return this.postDeploy(data);
data.timestamp = block.timestamp;
const balance = new web3Utils.BN(
await data.contract.interfaceAdapter.getBalance(tx.source)
);
const gasUsed = new web3Utils.BN(
tx.metadata.operation_result.consumed_gas
);
const storageUsed = new web3Utils.BN(
tx.metadata.operation_result.paid_storage_size_diff
);
const fee = new web3Utils.BN(tx.fee);
tx.metadata.operation_result.balance_updates.forEach(
update => (burn = burn.add(new web3Utils.BN(update.change)))
);
burn = burn.abs();
const value = new web3Utils.BN(tx.balance);
const cost = fee.add(value).add(burn);
data.from = tx.source;
data.balance = web3Utils.fromWei(balance, "mwei");
data.gasUsed = gasUsed.toString(10);
data.storageUsed = storageUsed.toString(10);
data.fee = web3Utils.fromWei(fee, "kwei");
data.burn = web3Utils.fromWei(burn, "mwei");
constructor (abiType) {
// skip the "int" part at the start
let M = abiType.substr(3)
if (!M.length) {
M = '256'
}
this.maxInt = new BN(2, 10).pow(new BN(M, 10))
this.minInt = this.maxInt.neg()
}
fieldType = () => NUMBER
// if geth returns null, try again!
if (!block) return this.postDeploy(data);
data.timestamp = block.timestamp;
const balance = new web3Utils.BN(
await data.contract.interfaceAdapter.getBalance(tx.source)
);
const gasUsed = new web3Utils.BN(
tx.metadata.operation_result.consumed_gas
);
const storageUsed = new web3Utils.BN(
tx.metadata.operation_result.paid_storage_size_diff
);
const fee = new web3Utils.BN(tx.fee);
tx.metadata.operation_result.balance_updates.forEach(
update => (burn = burn.add(new web3Utils.BN(update.change)))
);
burn = burn.abs();
const value = new web3Utils.BN(tx.balance);
const cost = fee.add(value).add(burn);
data.from = tx.source;
data.balance = web3Utils.fromWei(balance, "mwei");
data.gasUsed = gasUsed.toString(10);
data.storageUsed = storageUsed.toString(10);
data.fee = web3Utils.fromWei(fee, "kwei");
data.burn = web3Utils.fromWei(burn, "mwei");
data.value = web3Utils.fromWei(value, "mwei");
data.cost = web3Utils.fromWei(cost, "mwei");
const bn = x => new BN(x)
const bigExp = (x, y) => bn(x).mul(bn(10).pow(bn(y)))
isValid = val => {
if (Number.isNaN(parseInt(`${val}`, 10))) {
return false
}
try {
const bv = new BN(`${val}`, 10)
return bv.gte(this.minInt) && bv.lte(this.maxInt)
} catch (_) {
return false
}
}
sanitize = v => (v || '').trim()
constructor(describeJson) {
this.migrator = null;
this.deployer = null;
this.migration = null;
this.currentGasTotal = new web3Utils.BN(0);
this.currentCostTotal = new web3Utils.BN(0);
this.finalCostTotal = new web3Utils.BN(0);
this.deployments = 0;
this.separator = "\n";
this.summary = [];
this.currentFileIndex = -1;
this.blockSpinner = null;
this.currentBlockWait = "";
this.describeJson = describeJson;
this.messages = new MigrationsMessages(this);
}
getTotals() {
const gas = this.currentGasTotal.clone();
const cost = web3Utils.fromWei(this.currentCostTotal, "mwei");
this.finalCostTotal = this.finalCostTotal.add(this.currentCostTotal);
this.currentGasTotal = new web3Utils.BN(0);
this.currentCostTotal = new web3Utils.BN(0);
return {
gas: gas.toString(10),
cost: cost,
finalCost: web3Utils.fromWei(this.finalCostTotal, "mwei"),
deployments: this.deployments.toString()
};
}