tidyup after debug
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../build-info/8ba2e4b0974ed33fcf3e440a09ab408d.json"
|
||||
"buildInfo": "../../../../../build-info/2d51c1ee73b60d3841c3aaecda52bf9b.json"
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../build-info/8ba2e4b0974ed33fcf3e440a09ab408d.json"
|
||||
"buildInfo": "../../../../../build-info/2d51c1ee73b60d3841c3aaecda52bf9b.json"
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../../build-info/8ba2e4b0974ed33fcf3e440a09ab408d.json"
|
||||
"buildInfo": "../../../../../../build-info/2d51c1ee73b60d3841c3aaecda52bf9b.json"
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/8ba2e4b0974ed33fcf3e440a09ab408d.json"
|
||||
"buildInfo": "../../../../build-info/2d51c1ee73b60d3841c3aaecda52bf9b.json"
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"_format": "hh-sol-cache-2",
|
||||
"files": {
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/BandwidthGenerator.sol": {
|
||||
"lastModificationDate": 1643986468117,
|
||||
"contentHash": "1f4bbbb31f9012a87c619219c14b6529",
|
||||
"lastModificationDate": 1643991031913,
|
||||
"contentHash": "74194be7556a5b0ffe27ab54ae7da410",
|
||||
"sourceName": "contracts/BandwidthGenerator.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.8.10",
|
||||
@@ -581,45 +581,6 @@
|
||||
"Strings"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/BandwidthGeneratorNoGravity.sol": {
|
||||
"lastModificationDate": 1643985412193,
|
||||
"contentHash": "973f6312352e196a40bc6aba31df58e4",
|
||||
"sourceName": "contracts/BandwidthGeneratorNoGravity.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
"runs": 200
|
||||
},
|
||||
"outputSelection": {
|
||||
"*": {
|
||||
"*": [
|
||||
"abi",
|
||||
"evm.bytecode",
|
||||
"evm.deployedBytecode",
|
||||
"evm.methodIdentifiers"
|
||||
],
|
||||
"": [
|
||||
"ast"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"./CosmosToken.sol",
|
||||
"@openzeppelin/contracts/access/Ownable.sol",
|
||||
"@openzeppelin/contracts/utils/math/SafeMath.sol",
|
||||
"hardhat/console.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
"0.8.10"
|
||||
],
|
||||
"artifacts": [
|
||||
"BandwidthGeneratorNoGravity"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/hardhat/console.sol": {
|
||||
"lastModificationDate": 1641812555138,
|
||||
"contentHash": "cc4777addd464ea56fa35b1c45df0591",
|
||||
@@ -653,6 +614,45 @@
|
||||
"artifacts": [
|
||||
"console"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/debug/BandwidthGeneratorNoGravity.sol": {
|
||||
"lastModificationDate": 1643991077561,
|
||||
"contentHash": "bd97e288bf24ad18aa0cefbefd71ea15",
|
||||
"sourceName": "contracts/debug/BandwidthGeneratorNoGravity.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
"runs": 200
|
||||
},
|
||||
"outputSelection": {
|
||||
"*": {
|
||||
"*": [
|
||||
"abi",
|
||||
"evm.bytecode",
|
||||
"evm.deployedBytecode",
|
||||
"evm.methodIdentifiers"
|
||||
],
|
||||
"": [
|
||||
"ast"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"../CosmosToken.sol",
|
||||
"@openzeppelin/contracts/access/Ownable.sol",
|
||||
"@openzeppelin/contracts/utils/math/SafeMath.sol",
|
||||
"hardhat/console.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
"0.8.10"
|
||||
],
|
||||
"artifacts": [
|
||||
"BandwidthGeneratorNoGravity"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,13 @@
|
||||
{"rinkeby":{"NYM_ERC20":"0x1f0e8a26f223483b8307a65c37dae0322eb04720","BANDWIDTH_GENERATOR":"0xd9006A128B4daC3E15769a7fd36Cc1A1192844Ce","GRAVITY":"0xe58c12f8bA4a28e87841b10BdEdf80A47F86BA9B","TEST_GRAVITY":"0x8383D4741e926549c9B42938B512A0fbF6Ccc8A0","BANDWIDTH_GENERATOR_NO_GRAVITY":"0x72b572d5Af5ceebb89e7Af1eda7868A1013347C9"},"mainnet":{"NYM_ERC20":"0x525A8F6F3Ba4752868cde25164382BfbaE3990e1","NYMT":"0xE8883BAeF3869e14E4823F46662e81D4F7d2A81F","BANDWIDTH_GENERATOR":"","BANDWIDTH_GENERATOR_NYMT":"0xB3BF30DD53044c9050B7309031Bbf26b2cecF3be","GRAVITY":"0xa4108aA1Ec4967F8b52220a4f7e94A8201F2D906"}}
|
||||
{"rinkeby":{
|
||||
"NYM_ERC20":"0x1f0e8a26f223483b8307a65c37dae0322eb04720",
|
||||
"BANDWIDTH_GENERATOR":"0xd9006A128B4daC3E15769a7fd36Cc1A1192844Ce",
|
||||
"GRAVITY":"0xe58c12f8bA4a28e87841b10BdEdf80A47F86BA9B",
|
||||
"TEST_GRAVITY":"0x8383D4741e926549c9B42938B512A0fbF6Ccc8A0",
|
||||
"BANDWIDTH_GENERATOR_NO_GRAVITY":"0x72b572d5Af5ceebb89e7Af1eda7868A1013347C9"
|
||||
},"mainnet":{
|
||||
"NYM_ERC20":"0x525A8F6F3Ba4752868cde25164382BfbaE3990e1",
|
||||
"NYMT":"0xE8883BAeF3869e14E4823F46662e81D4F7d2A81F",
|
||||
"BANDWIDTH_GENERATOR":"",
|
||||
"BANDWIDTH_GENERATOR_NYMT":"0xB3BF30DD53044c9050B7309031Bbf26b2cecF3be",
|
||||
"GRAVITY":"0xa4108aA1Ec4967F8b52220a4f7e94A8201F2D906"
|
||||
}}
|
||||
@@ -16,7 +16,7 @@ import "@openzeppelin/contracts/utils/math/SafeMath.sol";
|
||||
* Credentials represent a certain amount of bandwidth which can be sent through the Nym Mixnet.
|
||||
* By default 1 NYM = 1 GB of bandwidth. The `BytesPerToken` amount can be adjusted by the contract owner.
|
||||
* The amount of bandwidth bought is calculated according to the following formula:
|
||||
* `(Token amount in 'wei' / 10**18) * BytesPerToken`
|
||||
* `(Token amount in 'wei' / 10**6) * BytesPerToken`
|
||||
*/
|
||||
contract BandwidthGenerator is Ownable {
|
||||
|
||||
@@ -107,7 +107,7 @@ contract BandwidthGenerator is Ownable {
|
||||
|
||||
function bandwidthFromToken(uint256 _amount) public view returns (uint256) {
|
||||
uint256 amountMulBytes = _amount.mul(BytesPerToken);
|
||||
return amountMulBytes.div(10**6); // was 10**18, changed to 10**6 because of cosmos decimals
|
||||
return amountMulBytes.div(10**6);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-13
@@ -1,10 +1,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
pragma solidity 0.8.10;
|
||||
|
||||
import "./CosmosToken.sol";
|
||||
// import "./Gravity.sol";
|
||||
import "../CosmosToken.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
|
||||
import "hardhat/console.sol";
|
||||
|
||||
/**
|
||||
* @title BandwidthGenerator
|
||||
@@ -23,7 +23,6 @@ contract BandwidthGeneratorNoGravity is Ownable {
|
||||
using SafeMath for uint256;
|
||||
|
||||
CosmosERC20 public erc20;
|
||||
// Gravity public gravityBridge;
|
||||
uint256 public BytesPerToken;
|
||||
bool public credentialGenerationEnabled;
|
||||
|
||||
@@ -52,9 +51,7 @@ contract BandwidthGeneratorNoGravity is Ownable {
|
||||
*/
|
||||
constructor(CosmosERC20 _erc20) {
|
||||
require(address(_erc20) != address(0), "BandwidthGenerator: erc20 address cannot be null");
|
||||
// require(address(_gravityBridge) != address(0), "BandwidthGenerator: gravity bridge address cannot be null");
|
||||
erc20 = _erc20;
|
||||
// gravityBridge = _gravityBridge;
|
||||
BytesPerToken = 1073741824; // default amount set at deployment: 1 erc20NYM = 1073741824 Bytes = 1GB
|
||||
credentialGenerationEnabled = true;
|
||||
}
|
||||
@@ -87,15 +84,12 @@ contract BandwidthGeneratorNoGravity is Ownable {
|
||||
* @param _cosmosRecipient Address of the recipient of payment on Nym Cosmos Blockchain.
|
||||
*/
|
||||
function generateBasicBandwidthCredential(uint256 _amount, uint256 _verificationKey, bytes memory _signedVerificationKey, string calldata _cosmosRecipient) public checkEnabled {
|
||||
require(_signedVerificationKey.length == 64, "BandwidthGenerator: Signature doesn't have 64 bytes");
|
||||
// temporarily removed this check
|
||||
// require(_signedVerificationKey.length == 64, "BandwidthGenerator: Signature doesn't have 64 bytes");
|
||||
erc20.transferFrom(msg.sender, address(this), _amount);
|
||||
// erc20.approve(address(gravityBridge), _amount);
|
||||
// gravityBridge.sendToCosmos(
|
||||
// address(erc20),
|
||||
// _cosmosRecipient,
|
||||
// _amount
|
||||
// );
|
||||
console.log(_amount);
|
||||
uint256 bandwidth = bandwidthFromToken(_amount);
|
||||
console.log(bandwidth);
|
||||
emit BBCredentialPurchased(
|
||||
bandwidth,
|
||||
_verificationKey,
|
||||
@@ -106,7 +100,8 @@ contract BandwidthGeneratorNoGravity is Ownable {
|
||||
|
||||
function bandwidthFromToken(uint256 _amount) public view returns (uint256) {
|
||||
uint256 amountMulBytes = _amount.mul(BytesPerToken);
|
||||
return amountMulBytes.div(10**18);
|
||||
// return amountMulBytes.div(10**18);
|
||||
return amountMulBytes.div(10**6);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ async function main() {
|
||||
// if this is failing, check whether the ERC20 address has been manually added to the contract addresses json file
|
||||
const bandwidthGenerator = await BandwidthGenerator.deploy(
|
||||
contracts.rinkeby.NYM_ERC20,
|
||||
contracts.rinkeby.GRAVITY
|
||||
contracts.rinkeby.TEST_GRAVITY
|
||||
);
|
||||
|
||||
console.log("deploying...");
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
const { ethers } = require('hardhat');
|
||||
const { constants } = require('@openzeppelin/test-helpers');
|
||||
const contracts = require("../../contractAddresses.json");
|
||||
const fs = require('file-system');
|
||||
|
||||
async function main() {
|
||||
const [deployer] = await ethers.getSigners();
|
||||
console.log(deployer.address);
|
||||
console.log(constants.ZERO_BYTES32);
|
||||
const Gravity = await ethers.getContractFactory("TestGravity");
|
||||
// deploy with args from unit tests
|
||||
const gravity = await Gravity.deploy(
|
||||
constants.ZERO_BYTES32,
|
||||
[deployer.address],
|
||||
[2863311531]
|
||||
);
|
||||
|
||||
contracts.rinkeby.TEST_GRAVITY = gravity.address;
|
||||
// the location of the json file is relative to where you are running the script from - run from root of directory
|
||||
fs.writeFileSync('./contractAddresses.json', JSON.stringify(contracts), (err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
console.log(`gravity.sol deployed at ${gravity.address}`);
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,7 +1,6 @@
|
||||
// arguments for verification of gravity contract via hardhat-etherscan plugin
|
||||
module.exports = [
|
||||
"0xe58c12f8bA4a28e87841b10BdEdf80A47F86BA9B",
|
||||
"test",
|
||||
"tst",
|
||||
"0x8383D4741e926549c9B42938B512A0fbF6Ccc8A0",
|
||||
"testn",
|
||||
"testn",
|
||||
6
|
||||
];
|
||||
@@ -16,7 +16,7 @@ contract('BandwidthGenerator', (accounts) => {
|
||||
let cosmosRecipient = "nymt1f06hzmwf9chqewkpv93ajk6tayzp4784m2da9x"; // random sandbox testnet address
|
||||
let initialRatio = 1073741824; // 1073741824 bytes = 1GB
|
||||
let newRatio;
|
||||
let tokenAmount = 100000000;
|
||||
let tokenAmount = 100000000; // not using toWei as comsos erc20 token has 6 decimals instead of standard 18
|
||||
let halfTokenAmount = 50000000;
|
||||
let unevenTokenAmount = 11500000;
|
||||
let oneToken = 1000000;
|
||||
@@ -103,7 +103,7 @@ contract('BandwidthGenerator', (accounts) => {
|
||||
{ from: user }
|
||||
);
|
||||
|
||||
let expectedBandwidthInMB = ((halfTokenAmount/10**6)*initialRatio); // 50 * (1024*1024*1024) bytes = 51200MB = 50GB of bandwidth
|
||||
let expectedBandwidthInMB = ((halfTokenAmount/10**6)*initialRatio);
|
||||
|
||||
await expectEvent.inTransaction(tx.tx, bandwidthGenerator, 'BBCredentialPurchased', {
|
||||
Bandwidth: expectedBandwidthInMB.toString(),
|
||||
@@ -128,9 +128,6 @@ contract('BandwidthGenerator', (accounts) => {
|
||||
expect((await erc20token.balanceOf(user)).toString()).to.equal(halfTokenAmount.toString());
|
||||
});
|
||||
|
||||
/**
|
||||
* This can be out by a float still with amounts such as '.1'
|
||||
*/
|
||||
it("it transfers for uneven token amounts", async () => {
|
||||
let tx = await bandwidthGenerator.generateBasicBandwidthCredential(
|
||||
unevenTokenAmount,
|
||||
@@ -163,7 +160,7 @@ contract('BandwidthGenerator', (accounts) => {
|
||||
});
|
||||
});
|
||||
|
||||
it.skip("reverts when signed verification key !=64 bytes", async () => {
|
||||
it("reverts when signed verification key !=64 bytes", async () => {
|
||||
await erc20token.approve(bandwidthGenerator.address,(halfTokenAmount),{ from: user });
|
||||
|
||||
await expectRevert(
|
||||
@@ -222,7 +219,7 @@ contract('BandwidthGenerator', (accounts) => {
|
||||
_tokenContract: erc20token.address,
|
||||
_sender: bandwidthGenerator.address,
|
||||
_destination: cosmosRecipient,
|
||||
_amount: oneToken
|
||||
_amount: oneToken.toString()
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,236 +0,0 @@
|
||||
const { expect } = require("chai");
|
||||
const { constants, expectRevert, expectEvent } = require('@openzeppelin/test-helpers');
|
||||
const { artifacts, web3 } = require("hardhat");
|
||||
const BN = require('bn.js');
|
||||
const BandwidthGenerator = artifacts.require('BandwidthGeneratorNoGravity');
|
||||
const Gravity = artifacts.require('test-contracts/TestGravity');
|
||||
const CosmosToken = artifacts.require('TestCosmosERC20');
|
||||
|
||||
|
||||
contract('BandwidthGenerator', (accounts) => {
|
||||
let bandwidthGenerator;
|
||||
let gravity;
|
||||
let erc20token;
|
||||
let owner = accounts[0];
|
||||
let user = accounts[1];
|
||||
let cosmosRecipient = "nymt1f06hzmwf9chqewkpv93ajk6tayzp4784m2da9x"; // random sandbox testnet address
|
||||
let initialRatio = 1073741824; // 1073741824 bytes = 1GB
|
||||
let newRatio;
|
||||
let tokenAmount = web3.utils.toWei('100'); // this is converting 100 tokens to their representation in wei: 100000000000000000000
|
||||
let halfTokenAmount = web3.utils.toWei('50');
|
||||
let unevenTokenAmount = web3.utils.toWei('11.5'); // 11500000000000000000
|
||||
let oneToken = web3.utils.toWei('1');
|
||||
|
||||
before('deploy contracts', async () => {
|
||||
|
||||
// deploy gravity bridge with test data
|
||||
gravity = await Gravity.new(
|
||||
constants.ZERO_BYTES32,
|
||||
[owner],
|
||||
[2863311531]
|
||||
);
|
||||
|
||||
// deploy erc20 NYM from bridge
|
||||
await gravity.deployERC20(
|
||||
'cosmosNYMDenomination',
|
||||
'NYMERC20',
|
||||
'NYM',
|
||||
6
|
||||
);
|
||||
|
||||
// grab event args for getting token address
|
||||
const logs = await gravity.getPastEvents({
|
||||
fromBlock: 0,
|
||||
toBlock: "latest",
|
||||
});
|
||||
|
||||
// create contract abstraction of deployed erc20NYM with address from event args
|
||||
erc20token = await CosmosToken.at(logs[0].args._tokenContract);
|
||||
|
||||
// deploy bandwidthGenerator contract with contract address of erc20NYM & address of gravity bridge
|
||||
bandwidthGenerator = await BandwidthGenerator.new(erc20token.address);
|
||||
|
||||
});
|
||||
|
||||
context(">> deployment parameters are valid", () => {
|
||||
it("returns the correct erc20 address", async () => {
|
||||
expect((await bandwidthGenerator.erc20()).toString()).to.equal((erc20token.address).toString());
|
||||
});
|
||||
it("returns the correct initial BytesPerToken ratio", async () => {
|
||||
expect((await bandwidthGenerator.BytesPerToken()).toString()).to.equal((initialRatio).toString());
|
||||
});
|
||||
it("returns the correct contract admin", async () => {
|
||||
expect((await bandwidthGenerator.owner()).toString()).to.equal((owner).toString());
|
||||
});
|
||||
it("returns the correct default generation state: true", async () => {
|
||||
expect((await bandwidthGenerator.credentialGenerationEnabled())).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
context(">> deployment parameters are invalid", () => {
|
||||
it("cannot be deployed with invalid erc20 address (zero address)", async () => {
|
||||
expectRevert(
|
||||
BandwidthGenerator.new(constants.ZERO_ADDRESS),
|
||||
"BandwidthGenerator: erc20 address cannot be null"
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
context(">> generateBasicBandwidthCredential()", () => {
|
||||
before("mint tokens & approve", async () => {
|
||||
// transfer tokens to account which will create a BBCredential
|
||||
await erc20token.mintForUnitTesting(user, tokenAmount);
|
||||
// approve transfer to contract
|
||||
await erc20token.approve(bandwidthGenerator.address,(tokenAmount),{ from: user });
|
||||
});
|
||||
|
||||
it("transfers tokens to bridge and emits an event with the correct values: 50 erc20NYM = 50GB of bandwidth", async () => {
|
||||
let tx = await bandwidthGenerator.generateBasicBandwidthCredential(
|
||||
halfTokenAmount,
|
||||
15,
|
||||
[0x39, 0x53, 0x0a, 0x00, 0xea, 0xe2, 0xa5, 0xaa, 0xc8, 0x14, 0x42, 0x09, 0xcc, 0xac, 0x91, 0x7a, 0xe5, 0x6b, 0xf4, 0xa9, 0x58, 0x95, 0x44, 0xcb, 0x00, 0x20, 0xf9, 0x2f, 0xee, 0x35, 0xa3, 0xba,
|
||||
0x39, 0x53, 0x0a, 0x00, 0xea, 0xe2, 0xa5, 0xaa, 0xc8, 0x14, 0x42, 0x09, 0xcc, 0xac, 0x91, 0x7a, 0xe5, 0x6b, 0xf4, 0xa9, 0x58, 0x95, 0x44, 0xcb, 0x00, 0x20, 0xf9, 0x2f, 0xee, 0x35, 0xa3, 0xba],
|
||||
cosmosRecipient,
|
||||
{ from: user }
|
||||
);
|
||||
|
||||
let expectedBandwidthInMB = ((halfTokenAmount/10**18)*initialRatio); // 50 * (1024*1024*1024) bytes = 51200MB = 50GB of bandwidth
|
||||
|
||||
await expectEvent.inTransaction(tx.tx, bandwidthGenerator, 'BBCredentialPurchased', {
|
||||
Bandwidth: expectedBandwidthInMB.toString(),
|
||||
VerificationKey: '15',
|
||||
SignedVerificationKey: '0x39530a00eae2a5aac8144209ccac917ae56bf4a9589544cb0020f92fee35a3ba39530a00eae2a5aac8144209ccac917ae56bf4a9589544cb0020f92fee35a3ba',
|
||||
CosmosRecipient: cosmosRecipient
|
||||
});
|
||||
|
||||
await expectEvent.inTransaction(tx.tx, erc20token, 'Transfer', {
|
||||
from: user,
|
||||
to: bandwidthGenerator.address,
|
||||
});
|
||||
|
||||
expect((await erc20token.balanceOf(bandwidthGenerator.address)).toString()).to.equal(halfTokenAmount.toString());
|
||||
expect((await erc20token.balanceOf(user)).toString()).to.equal(halfTokenAmount.toString());
|
||||
});
|
||||
|
||||
/**
|
||||
* This can be out by a float still with amounts such as '.1'
|
||||
*/
|
||||
it("it transfers for uneven token amounts", async () => {
|
||||
let tx = await bandwidthGenerator.generateBasicBandwidthCredential(
|
||||
unevenTokenAmount,
|
||||
15,
|
||||
[0x39, 0x53, 0x0a, 0x00, 0xea, 0xe2, 0xa5, 0xaa, 0xc8, 0x14, 0x42, 0x09, 0xcc, 0xac, 0x91, 0x7a, 0xe5, 0x6b, 0xf4, 0xa9, 0x58, 0x95, 0x44, 0xcb, 0x00, 0x20, 0xf9, 0x2f, 0xee, 0x35, 0xa3, 0xba,
|
||||
0x39, 0x53, 0x0a, 0x00, 0xea, 0xe2, 0xa5, 0xaa, 0xc8, 0x14, 0x42, 0x09, 0xcc, 0xac, 0x91, 0x7a, 0xe5, 0x6b, 0xf4, 0xa9, 0x58, 0x95, 0x44, 0xcb, 0x00, 0x20, 0xf9, 0x2f, 0xee, 0x35, 0xa3, 0xba],
|
||||
cosmosRecipient,
|
||||
{ from: user }
|
||||
);
|
||||
|
||||
let newexpectedBandwidthInMB = ((11500000000000000000*initialRatio)/10**18);
|
||||
|
||||
await expectEvent.inTransaction(tx.tx, bandwidthGenerator, 'BBCredentialPurchased', {
|
||||
Bandwidth: newexpectedBandwidthInMB.toString(),
|
||||
VerificationKey: '15',
|
||||
SignedVerificationKey: '0x39530a00eae2a5aac8144209ccac917ae56bf4a9589544cb0020f92fee35a3ba39530a00eae2a5aac8144209ccac917ae56bf4a9589544cb0020f92fee35a3ba',
|
||||
CosmosRecipient: cosmosRecipient
|
||||
});
|
||||
|
||||
await expectEvent.inTransaction(tx.tx, erc20token, 'Transfer', {
|
||||
from: user,
|
||||
to: bandwidthGenerator.address,
|
||||
});
|
||||
|
||||
it("reverts when signed verification key !=64 bytes", async () => {
|
||||
await erc20token.approve(bandwidthGenerator.address,(halfTokenAmount),{ from: user });
|
||||
|
||||
await expectRevert(
|
||||
bandwidthGenerator.generateBasicBandwidthCredential(
|
||||
1,
|
||||
16,
|
||||
[0x0a, 0x00, 0xea, 0xe2, 0xa5, 0xaa, 0xc8, 0x14, 0x42, 0x09, 0xcc, 0xac, 0x91, 0x7a, 0xe5, 0x6b, 0xf4, 0xa9, 0x58, 0x95, 0x44, 0xcb, 0x00, 0x20, 0xf9, 0x2f, 0xee, 0x35, 0xa3, 0xba,
|
||||
0x39, 0x53, 0x0a, 0x00, 0xea, 0xe2, 0xa5, 0xaa, 0xc8, 0x14, 0x42, 0x09, 0xcc, 0xac, 0x91, 0x7a, 0xe5, 0x6b, 0xf4, 0xa9, 0x58, 0x95, 0x44, 0xcb, 0x00, 0x20, 0xf9, 0x2f, 0xee, 0x35, 0xa3, 0xba],
|
||||
cosmosRecipient,
|
||||
{ from: user }
|
||||
), "BandwidthGenerator: Signature doesn't have 64 bytes"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
context(">> changeRatio()", () => {
|
||||
it("only admin can change token to MB ratio", async () => {
|
||||
newRatio = 10 * initialRatio; // 10GB of bandwidth per 1 erc20NYM
|
||||
await expectRevert(
|
||||
bandwidthGenerator.changeRatio(newRatio, {from: user}),
|
||||
"Ownable: caller is not the owner"
|
||||
);
|
||||
});
|
||||
it("admin can change ratio, emits 'RatioChanged' event", async () => {
|
||||
let tx = await bandwidthGenerator.changeRatio(newRatio, {from: owner});
|
||||
await expectEvent.inTransaction(tx.tx, bandwidthGenerator, 'RatioChanged', {
|
||||
NewBytesPerToken: newRatio.toString()
|
||||
});
|
||||
expect((await bandwidthGenerator.BytesPerToken()).toString()).to.equal((newRatio).toString());
|
||||
});
|
||||
it("BBCredential represents new ratio after change: 1 erc20NYM = 10GB of bandwidth", async () => {
|
||||
let tx = await bandwidthGenerator.generateBasicBandwidthCredential(
|
||||
oneToken,
|
||||
15,
|
||||
[0x39, 0x53, 0x0a, 0x00, 0xea, 0xe2, 0xa5, 0xaa, 0xc8, 0x14, 0x42, 0x09, 0xcc, 0xac, 0x91, 0x7a, 0xe5, 0x6b, 0xf4, 0xa9, 0x58, 0x95, 0x44, 0xcb, 0x00, 0x20, 0xf9, 0x2f, 0xee, 0x35, 0xa3, 0xba,
|
||||
0x39, 0x53, 0x0a, 0x00, 0xea, 0xe2, 0xa5, 0xaa, 0xc8, 0x14, 0x42, 0x09, 0xcc, 0xac, 0x91, 0x7a, 0xe5, 0x6b, 0xf4, 0xa9, 0x58, 0x95, 0x44, 0xcb, 0x00, 0x20, 0xf9, 0x2f, 0xee, 0x35, 0xa3, 0xba],
|
||||
cosmosRecipient,
|
||||
{ from: user }
|
||||
);
|
||||
|
||||
let expectedBandwidthInMB = ((oneToken/10**18)*newRatio);
|
||||
|
||||
await expectEvent.inTransaction(tx.tx, bandwidthGenerator, 'BBCredentialPurchased', {
|
||||
Bandwidth: expectedBandwidthInMB.toString(),
|
||||
VerificationKey: '15',
|
||||
SignedVerificationKey: '0x39530a00eae2a5aac8144209ccac917ae56bf4a9589544cb0020f92fee35a3ba39530a00eae2a5aac8144209ccac917ae56bf4a9589544cb0020f92fee35a3ba',
|
||||
CosmosRecipient: cosmosRecipient
|
||||
});
|
||||
|
||||
await expectEvent.inTransaction(tx.tx, erc20token, 'Transfer', {
|
||||
from: user,
|
||||
to: bandwidthGenerator.address,
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
context(">>credential generation admin switch", () => {
|
||||
it("only admin can switch credential generation off", async () => {
|
||||
await expectRevert(
|
||||
bandwidthGenerator.credentialGenerationSwitch(false, { from: user }),
|
||||
"Ownable: caller is not the owner"
|
||||
)
|
||||
});
|
||||
it("admin can switch credential generation on/off & switch generates an event", async () => {
|
||||
let tx = await bandwidthGenerator.credentialGenerationSwitch(false);
|
||||
expect((await bandwidthGenerator.credentialGenerationEnabled())).to.equal(false);
|
||||
|
||||
await expectEvent.inTransaction(tx.tx, bandwidthGenerator, 'CredentialGenerationSwitch', {
|
||||
Enabled: false,
|
||||
});
|
||||
|
||||
tx = await bandwidthGenerator.credentialGenerationSwitch(true);
|
||||
expect((await bandwidthGenerator.credentialGenerationEnabled())).to.equal(true);
|
||||
|
||||
await expectEvent.inTransaction(tx.tx, bandwidthGenerator, 'CredentialGenerationSwitch', {
|
||||
Enabled: true,
|
||||
});
|
||||
});
|
||||
it("cannot generate credentials if switch = false", async () => {
|
||||
await bandwidthGenerator.credentialGenerationSwitch(false);
|
||||
await expectRevert(
|
||||
bandwidthGenerator.generateBasicBandwidthCredential(
|
||||
oneToken,
|
||||
15,
|
||||
[0x39, 0x53, 0x0a, 0x00, 0xea, 0xe2, 0xa5, 0xaa, 0xc8, 0x14, 0x42, 0x09, 0xcc, 0xac, 0x91, 0x7a, 0xe5, 0x6b, 0xf4, 0xa9, 0x58, 0x95, 0x44, 0xcb, 0x00, 0x20, 0xf9, 0x2f, 0xee, 0x35, 0xa3, 0xba,
|
||||
0x39, 0x53, 0x0a, 0x00, 0xea, 0xe2, 0xa5, 0xaa, 0xc8, 0x14, 0x42, 0x09, 0xcc, 0xac, 0x91, 0x7a, 0xe5, 0x6b, 0xf4, 0xa9, 0x58, 0x95, 0x44, 0xcb, 0x00, 0x20, 0xf9, 0x2f, 0xee, 0x35, 0xa3, 0xba],
|
||||
cosmosRecipient,
|
||||
{ from: user }
|
||||
), "BandwidthGenerator: credential generation isn't currently enabled"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
Reference in New Issue
Block a user