Skip to content

Commit

Permalink
Updated tests and included contract deployment tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Nov 16, 2021
1 parent 1ee4393 commit 4b5ce21
Showing 1 changed file with 70 additions and 29 deletions.
99 changes: 70 additions & 29 deletions src.ts/index.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,62 @@ import { BigNumber, ethers } from "ethers";
import { JsonRpcProvider } from ".";

const Tests = {
// Blocks should only be tested after 1121818, per Telegram discussion
// Only recent blocks and transactions work, so these tests need
// to be periodically updated.
Blocks: [

{
hash: '0x19e5ebcc8d2c1ca40c04ee74164616ebd1d099a69820f83d206d5a5d2f38941e',
parentHash: '0x24fd17014507aaad94a89688bae98860ef5f022c73d1c5f6c7820f10573ed45f',
number: 5150897,
timestamp: 1629226634,
hash: '0x5ef9916c4808d908d6e0bc578f6cc637221e8177732ddcb25311f26694cd1d59',
parentHash: '0x27e045b1f9fbb3e7ef763df07cf7f664146dd2413eaa22daab32793f82b77bf6',
number: 7269300,
timestamp: 1637020948,
nonce: '0x0000000000000000',
difficulty: 0,
gasLimit: BigNumber.from("0xffffffff"),
gasUsed: BigNumber.from("0x00"),
miner: '0x7a503503558C8281B3d00455dDb3497b958F23da',
miner: '0x555299c39b76896f96A02682F56F8bFa47dE248D',
extraData: '0x',
transactions: []
}
},
],
Transactions: [
{
hash: '0x569390a6ea347950ca460ea1f70e8fa79b01ec37615ef4c709c1bbd9e3ee3fc1',
hash: '0xfb7b98aaf9028866eb0308a4e9ddf8388278870af524ae30665d3113458728e2',
type: 0,
accessList: null,
blockHash: '0x34a360f9eec4a394cc4a0bb43dd13ff747a709b3384be317e9b69366c49d1dae',
blockNumber: 5150948,
blockHash: '0xd441ff6d99de0a314e88357a1230a1968e78aea3e1284774148947fee3489bdc',
blockNumber: 7269402,
transactionIndex: 0,
from: '0x8522395fdca22e59b6F8d0bA2579ACd5877f50b7',
gasPrice: BigNumber.from("0x05f5e100"),
gasLimit: BigNumber.from('0x7b0c'),
gasLimit: BigNumber.from("0x7b0c"),
to: '0x8522395fdca22e59b6F8d0bA2579ACd5877f50b7',
value: BigNumber.from('0x01'),
nonce: 4,
value: BigNumber.from("0x01"),
nonce: 9,
data: '0x',
r: '0x92be234a54bc1300f0fd8698e1e916857c4a05894625c82f6ca3f15999de8050',
s: '0x5a441e023331b8d2763c4e5f93700b84b3cf7af6e4f96e72db50c0cb4e0ec5e1',
v: 165,
r: '0xaf9fdcfbf62763ab76d7fbdec8920c6e13ca6b70b673d106fb28a504acc9dc43',
s: '0x13fdb9206daba92298ff5c293ea2ed5507407b97cf4dc21c562db40a06932d8a',
v: 166,
creates: null,
chainId: 65,
}
},
],
TransactionReceipts: [
{
to: '0x8522395fdca22e59b6F8d0bA2579ACd5877f50b7',
from: '0x8522395fdca22e59b6F8d0bA2579ACd5877f50b7',
contractAddress: null,
transactionIndex: 0,
gasUsed: BigNumber.from('0x5208'),
gasUsed: BigNumber.from("0x5208"),
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0x34a360f9eec4a394cc4a0bb43dd13ff747a709b3384be317e9b69366c49d1dae',
transactionHash: '0x569390a6ea347950ca460ea1f70e8fa79b01ec37615ef4c709c1bbd9e3ee3fc1',
blockHash: '0xd441ff6d99de0a314e88357a1230a1968e78aea3e1284774148947fee3489bdc',
transactionHash: '0xfb7b98aaf9028866eb0308a4e9ddf8388278870af524ae30665d3113458728e2',
logs: [],
blockNumber: 5150948,
cumulativeGasUsed: BigNumber.from('0x5208'),
blockNumber: 7269402,
cumulativeGasUsed: BigNumber.from("0x5208"),
status: 1,
type: 0,
byzantium: true
}
},
],
};

Expand Down Expand Up @@ -94,7 +94,7 @@ export function equals(actual: any, expected: any): boolean {
return true;
}

describe("Test BscscanProvider", function() {
describe("Test ExchainProvider", function() {
const provider = new JsonRpcProvider("https:/\/exchaintestrpc.okex.org");

// A secret we can use in our testcases for wallets and such
Expand All @@ -108,16 +108,57 @@ describe("Test BscscanProvider", function() {
})();

if (secret) {
it("Sends a transaction", async function() {
const wallet = new ethers.Wallet(ethers.utils.id(secret), provider);

it("Displays secret account details", async function() {
this.timeout(60000);
const wallet = new ethers.Wallet(ethers.utils.id(secret), provider);

console.log("Wallet:", wallet.address);
console.log("Balance", ethers.utils.formatEther(await wallet.getBalance()));
});

it("Sends a transaction", async function() {
this.timeout(180000);

const tx = await wallet.sendTransaction({ to: wallet.address, value: 1 });
//console.log(tx);
console.log(tx);
await tx.wait();
});

const bytecode = "0x608060405234801561001057600080fd5b50610150806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806360fe47b11461003b5780636d4ce63c14610057575b600080fd5b6100556004803603810190610050919061009d565b610075565b005b61005f61007f565b60405161006c91906100d9565b60405180910390f35b8060008190555050565b60008054905090565b60008135905061009781610103565b92915050565b6000602082840312156100b3576100b26100fe565b5b60006100c184828501610088565b91505092915050565b6100d3816100f4565b82525050565b60006020820190506100ee60008301846100ca565b92915050565b6000819050919050565b600080fd5b61010c816100f4565b811461011757600080fd5b5056fea26469706673582212207c54d252a58b2a42da91ec168afc7481043a6b01121ba19e19e4343be3decc7564736f6c63430008070033";
const runtimeBytecode = "0x608060405234801561001057600080fd5b50600436106100365760003560e01c806360fe47b11461003b5780636d4ce63c14610057575b600080fd5b6100556004803603810190610050919061009d565b610075565b005b61005f61007f565b60405161006c91906100d9565b60405180910390f35b8060008190555050565b60008054905090565b60008135905061009781610103565b92915050565b6000602082840312156100b3576100b26100fe565b5b60006100c184828501610088565b91505092915050565b6100d3816100f4565b82525050565b60006020820190506100ee60008301846100ca565b92915050565b6000819050919050565b600080fd5b61010c816100f4565b811461011757600080fd5b5056fea26469706673582212207c54d252a58b2a42da91ec168afc7481043a6b01121ba19e19e4343be3decc7564736f6c63430008070033";

const abi = [
"function set(uint256)",
"function get() view returns (uint)"
];

it ("Deploys a ccontract", async function() {
this.timeout(180000);
const factory = new ethers.ContractFactory(abi, bytecode, wallet);
const contract = await factory.deploy();
await contract.deployTransaction.wait();
const data = await provider.getCode(contract.address);
assert.equal(data, runtimeBytecode, "deployed bytecode is correct");
});
}

it("Fetches Block Number", async function() {
this.timeout(60000);
const blockNumber = await provider.getBlockNumber();
assert.ok(typeof(blockNumber) === "number");
/*
console.log("Block Number:", blockNumber);
// Use this to find blocks with transactions for tests
let scan = blockNumber;
while (true) {
scan++;
const block = await provider.getBlock(scan);
console.log("BLOCK", block);
}
*/
});

Tests.Blocks.forEach((test) => {
it(`fetches block #${ test.number }`, async function() {
this.timeout(60000);
Expand All @@ -142,7 +183,7 @@ describe("Test BscscanProvider", function() {
it(`fetches transaction Receipt: ${ test.transactionHash.substring(0, 10) }`, async function() {
this.timeout(60000);
const receipt = await provider.getTransactionReceipt(test.transactionHash);
//console.log("REC", receipt);
//console.log("RECEIPT", receipt);
assert.ok(typeof(receipt.confirmations) === "number", "missing confirmations");
equals(receipt, test)
});
Expand Down

0 comments on commit 4b5ce21

Please sign in to comment.