|
| 1 | +import { ethers, network } from "hardhat" |
| 2 | +import * as utils from "./utils" |
| 3 | + |
| 4 | +import { VerifRegApiTest, VerifRegApiTest__factory } from "../typechain-types" |
| 5 | +import { assert } from "console" |
| 6 | + |
| 7 | +const DBG_LOG_ON = false |
| 8 | + |
| 9 | +//RUN using: |
| 10 | +//npx hardhat --network calibnet run hh-test/verifreg_deserial.t.ts |
| 11 | + |
| 12 | +const main = async () => { |
| 13 | + const deployerPk = network.config.accounts[0] |
| 14 | + |
| 15 | + const provider = new ethers.providers.JsonRpcProvider(network.config.url) |
| 16 | + |
| 17 | + const deployer = new ethers.Wallet(deployerPk, provider) |
| 18 | + |
| 19 | + console.log(`\nDeploying contracts... (verifreg)\n`) |
| 20 | + |
| 21 | + const fact = new VerifRegApiTest__factory() |
| 22 | + |
| 23 | + const verifreg = await fact.connect(deployer).deploy() |
| 24 | + |
| 25 | + await utils.delay(15_000) |
| 26 | + |
| 27 | + console.log(`\nCalling: get_claims(...)\n`) |
| 28 | + |
| 29 | + //fil-sol issue#51 example values |
| 30 | + const claimObject = { provider: 33601, claim_ids: [27133] } |
| 31 | + |
| 32 | + const replicateFirstClaimId = (claimObject, n) => { |
| 33 | + const claim_ids = [...new Array(10)].map(() => claimObject.claim_ids[0]) |
| 34 | + return { ...claimObject, claim_ids } |
| 35 | + } |
| 36 | + |
| 37 | + //fetch and compare all results with the initial request |
| 38 | + const resOne = await verifreg.get_claims(claimObject) |
| 39 | + dbgLogRes(`resOne:`, resOne) |
| 40 | + |
| 41 | + for (let len = 2; len < 10; len += 1) { |
| 42 | + const replicatedClaimObject = replicateFirstClaimId(claimObject, len) |
| 43 | + const resReplicated = await verifreg.get_claims(replicatedClaimObject) |
| 44 | + dbgLogRes(`resReplicated:::${len}:`, resReplicated) |
| 45 | + |
| 46 | + //check correctness |
| 47 | + const bigNumberKeys = ["provider", "client", "size", "term_min", "term_max", "term_start", "sector"] |
| 48 | + for (const repClaim of resReplicated.claims) { |
| 49 | + for (const bnk of bigNumberKeys) { |
| 50 | + assert(repClaim[bnk].eq(resOne.claims[0][bnk]), `ERR: replicated(${len}).claim.${bnk} !== resOne.claim.${bnk}!`) |
| 51 | + } |
| 52 | + assert(repClaim.data === resOne.claims[0].data, `ERR: replicated(${len}).data !== resOne.data!`) |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + console.log(`----> Verifreg deserialize. test completed!\n`) |
| 57 | +} |
| 58 | +main().catch((error) => { |
| 59 | + console.error(error) |
| 60 | + process.exitCode = 1 |
| 61 | +}) |
| 62 | + |
| 63 | +const dbgLogRes = (name, res) => { |
| 64 | + if (DBG_LOG_ON === false) return |
| 65 | + console.log(`\n---------> `, name) |
| 66 | + console.log("success_count", res.batch_info.success_count) |
| 67 | + console.log("fail_codes", res.batch_info.fail_codes) |
| 68 | + console.log("claims", res.claims) |
| 69 | +} |
0 commit comments