Skip to content

Commit

Permalink
Merge pull request #41 from ixofoundation/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Michael-Ixo authored Jun 22, 2023
2 parents f75bab6 + d42b688 commit 98c5dd2
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 369 deletions.
193 changes: 45 additions & 148 deletions __tests__/flows/claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { WalletUsers } from "../helpers/constants";
import {
CarbonCredentialsWorkerUrl,
EcsCredentialsWorkerUrl,
ProspectCredentialsWorkerUrl,
adminEntityAccounts,
dids,
} from "../setup/constants";
Expand Down Expand Up @@ -150,26 +151,26 @@ export const claimsBasic = () =>
export const supamotoClaims = () =>
describe("Testing the Claims module", () => {
// Set tester as root ecs user
// beforeAll(() =>
// Promise.all([
// generateNewWallet(WalletUsers.tester, process.env.ROOT_ECS),
// generateNewWallet(WalletUsers.oracle, process.env.ASSERT_USER_ECS),
// generateNewWallet(
// WalletUsers.bob,
// process.env.ASSERT_USER_PROSPECT_ORACLE
// ),
// generateNewWallet(
// WalletUsers.charlie,
// process.env.ASSERT_USER_CARBON_ORACLE
// ),
// ])
// );
beforeAll(() =>
Promise.all([
generateNewWallet(WalletUsers.tester, process.env.ROOT_ECS),
generateNewWallet(WalletUsers.oracle, process.env.ASSERT_USER_ECS),
generateNewWallet(
WalletUsers.bob,
process.env.ASSERT_USER_PROSPECT_ORACLE
),
generateNewWallet(
WalletUsers.charlie,
process.env.ASSERT_USER_CARBON_ORACLE
),
])
);

// if (chainNetwork === "devnet") {
// // helper to send funds to an admin account
// testMsg("test Bank Send to admin account", () =>
// Cosmos.BankSendTrx(
// 10000000000,
// 100000000000,
// WalletUsers.alice,
// undefined,
// undefined,
Expand All @@ -191,9 +192,9 @@ export const supamotoClaims = () =>
// testMsg("/ixo.claims.v1beta1.MsgCreateCollection", async () => {
// // add wait according to chunk index for ipfs rate limit
// console.log(
// "waiting 3 mintues as blocksync needs 5 minutes to load all ipfs files for entity external Ids"
// "waiting 5 mintues as blocksync needs 5 minutes to load all ipfs files for entity external Ids"
// );
// await timeout(1000 * 60 * 3);
// // await timeout(1000 * 60 * 5);

// const res = await Claims.CreateCollectionSupamotoGenesis(
// dids.assetCollection,
Expand Down Expand Up @@ -290,23 +291,25 @@ export const supamotoClaims = () =>

// devide payments per device into 50 devices at a time
// ==============================================================
purchaseData = chunkArray<any[]>(Object.values(purchaseData), 16);
purchaseData = chunkArray<any[]>(Object.values(purchaseData), 30);
let stovePurchasesAll: any[] = [];
let index = -1;
// console.dir(
// {
// length: purchaseData.length,
// groups: purchaseData.map((p) => {
// const devices = p.map((d) => d.length);
// return { devices, total: devices.reduce((a, b) => a + b, 0) };
// // return { devices, total: devices.reduce((a, b) => a + b, 0) };
// return { total: devices.reduce((a, b) => a + b, 0) };
// }),
// },
// { depth: null }
// );

console.time("claims");
for (const stovePurchases of purchaseData) {
index++;
// if (index !== 0) break; // if want to only mint a certain amount of batches add number here
// if (index !== 0) continue; // if want to only mint a certain amount of batches add number here
console.log(
"starting batch " + (index + 1) + " of " + purchaseData.length
);
Expand Down Expand Up @@ -346,145 +349,37 @@ export const supamotoClaims = () =>
fpClaimIds.length + " FuelPurchase claims successfully created"
);

// wait 15 seconds for claims to be indexed
await timeout(15 * 1000);

// save fuelPurchase claim ids per purchase
stovePurchases.forEach((ps: any[], i) => {
ps.forEach((p: any, j) => {
stovePurchases[i][j].fuelPurchaseClaimId = fpClaimIds.shift();
});
});

// create CER claims for each purchase that has a postceding purchase
const cerClaims = await axios.post(
EcsCredentialsWorkerUrl + "claims/create",
// evaluate fuelPurchase claims
const fpEvaluations = await axios.post(
ProspectCredentialsWorkerUrl + "claims/evaluate",
{
type: "CER",
collectionId: "1",
storage: "cellnode",
generate: {
type: "CER",
data: stovePurchases
.flat(1)
.map((p: any, i, arr) => {
const nextPurchase = arr[i + 1];
// if no next purchase for device then dont make cer claim
if (!nextPurchase || nextPurchase.device_id !== p.device_id)
return null;
return {
fuelPurchaseClaimId: p.fuelPurchaseClaimId, // fuel purchase claim id
startDate: p.time_paid, // start date (current fpClaim date)
endDate: nextPurchase.time_paid, // end date (next fpClaim date)
};
})
.filter((d) => !!d),
},
evaluations: fpClaimIds.map((id) => ({
claimId: id,
reason: 1,
status: ixo.claims.v1beta1.EvaluationStatus.APPROVED,
oracle: dids.prospectOracle,
verificationProof: "proof",
})),
},
{ headers: { Authorization: process.env.ECS_CREDENTIAL_WORKER_AUTH } }
{
headers: {
Authorization: process.env.PROSPECT_CREDENTIAL_WORKER_AUTH,
},
}
);
assertIsDeliverTxSuccess(cerClaims.data);
const cerClaimIds: string[] = utils.common.getValuesFromEvents(
cerClaims.data,
"ixo.claims.v1beta1.ClaimSubmittedEvent",
"claim",
(c) => c.claim_id
assertIsDeliverTxSuccess(fpEvaluations.data);
console.log(
fpClaimIds.length + " FuelPurchase claims successfully evaluated"
);
console.log(cerClaimIds.length + " CER claims successfully created");

// save cer claim ids per purchase
// save fuelPurchase claim ids per purchase
stovePurchases.forEach((ps: any[], i) => {
ps.forEach((p: any, j) => {
if (ps.length - 1 === j) return;
stovePurchases[i][j].cerClaimId = cerClaimIds.shift();
stovePurchases[i][j].fuelPurchaseClaimId = fpClaimIds.shift();
});
});

// wait 7 seconds for claims to be indexed
// await timeout(1000 * 7);

// create VER evaluations for cer claim in batches of 25 with cellnode ipfs rate limit being 30 per 10s
// const now = new Date();
// const verEvaluationsData = chunkArray<any>(
// stovePurchases
// .flat(1)
// .map((p: any) => {
// // if no cer claim then dont do ver evaluation
// if (!p.cerClaimId) return null;
// return {
// claimId: p.cerClaimId,
// reason: 1,
// status: ixo.claims.v1beta1.EvaluationStatus.APPROVED,
// oracle: dids.carbonOracle,
// generate: {
// type: "VER",
// data: [
// {
// CERClaimId: p.cerClaimId, // claim id of CER claim
// validFrom: p.time_paid, // date that credentail is valid from
// status: "verified", // status of the credential
// factor: 11.48, // emission reduction factor
// evaluation: {
// model: "Awesome", // model used to calculate the emission reduction
// version: "1.0.0", // version of the model
// date: now, // date of model calculation
// },
// },
// ],
// },
// };
// })
// .filter((d) => !!d),
// 25
// );
// let verIndex = -1;
// for (const evaluations of verEvaluationsData) {
// verIndex++;
// console.log(
// "starting ver batch " +
// (verIndex + 1) +
// " of " +
// verEvaluationsData.length
// );
// // wait for cellnode rate limit per 10s
// // if (verIndex) await timeout(1000 * 10);

// const verEvaluations = await axios.post(
// CarbonCredentialsWorkerUrl + "claims/certify",
// {
// type: "VER",
// collectionId: "1",
// storage: "ipfs",
// evaluationCreds: evaluations,
// },
// {
// headers: {
// Authorization: process.env.CARBON_CREDENTIAL_WORKER_AUTH,
// },
// timeout: 1000 * 60 * 5,
// }
// );
// assertIsDeliverTxSuccess(verEvaluations.data);

// // wait 10 seconds for evaluations to be indexed
// await timeout(10 * 1000);

// // mint tokens ver evaluations
// const mintTokens = await axios.post(
// CarbonCredentialsWorkerUrl + "tokens/mintFromVER",
// {
// name: "CARBON",
// claimIds: evaluations.map((e) => e.claimId),
// },
// {
// headers: {
// Authorization: process.env.CARBON_CREDENTIAL_WORKER_AUTH,
// },
// timeout: 1000 * 60 * 5,
// }
// );
// assertIsDeliverTxSuccess(mintTokens.data);
// }
// console.log("VER claims successfully created and tokens minted");
console.timeLog("claims");
// add current stove purchases chunk to all stove purchases
Expand All @@ -501,6 +396,8 @@ export const supamotoClaims = () =>
expect(true).toBeTruthy();
});

// OLD DUMMY CLAIMS
// ===============================
// let claimIds = [
// utils.common.generateId(10),
// utils.common.generateId(10),
Expand Down
28 changes: 16 additions & 12 deletions __tests__/flows/quickQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,28 +130,32 @@ export const quickQueries = () =>
// const user = (await getUser(WalletUsers.tester).getAccounts())[0].address;
// const contractAddress =
// "ixo1nc5tatafv6eyq7llkr2gv50ff9e22mnf70qgjlv737ktmt4eswrqvg5w3c";
// const tokens = ["0ae9ee3f43c92806232971ee67e23e22"];
// const tokens = [
// "247bf50a1ce28ea7622ef6082e5e559f",
// "3187434c0a27fc17e1f484812e6be90e",
// "32fe8cdc405b2c5828e59c2432eb615a",
// ];
// const msg = {
// balance: {
// owner: user,
// token_id: tokens[0],
// },
// // balance: {
// // owner: "ixo1jacj68c9uffdjt0yw6mumkxzcmup7la2yhfs72",
// // token_id: tokens[0],
// // },
// // tokens: {
// // owner: user,
// // owner: "ixo1jacj68c9uffdjt0yw6mumkxzcmup7la2yhfs72",
// // },
// // batch_balance: {
// // owner: user,
// // token_ids: tokens,
// // },
// // token_info: {
// // token_id: tokens[0],
// // },
// token_info: {
// token_id: tokens[0],
// },
// };
// const res = await queryClient.cosmwasm.wasm.v1.smartContractState({
// address: contractAddress,
// queryData: utils.conversions.JsonToArray(JSON.stringify(msg)),
// });
// console.log(utils.conversions.Uint8ArrayToJS(res.data));
// console.dir(utils.conversions.Uint8ArrayToJS(res.data), { depth: null });
// expect(res).toBeTruthy();
// });

Expand All @@ -172,9 +176,9 @@ export const quickQueries = () =>

// test("query token metadata by id", async () => {
// const res = await queryClient.ixo.token.v1beta1.tokenMetadata({
// id: "d89fc11cef9424891fdf9ae173f88a6e",
// id: "01a86ad8ffd270dc2d729365201debba",
// });
// console.log(res);
// console.dir(res, { depth: null });
// expect(res).toBeTruthy();
// });

Expand Down
22 changes: 11 additions & 11 deletions __tests__/setup/index.setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,36 @@ beforeAll(() => generateWallets(false));
// Setup flow for dao and group creations
// ------------------------------------------
// first create god classes and save 4 top classes dids in ./constants.ts
// classesFlow(); //impacts user
classesFlow(); //impacts user

// next create impacts dao and save impactsRootUserDid and impactsDao in ./constants.ts
// impactsFlow(); //impacts user
impactsFlow(); //impacts user

// next create emerging dao to save emergingDao to ./constants.ts
// emergingDaoFlow(); //emerging user
emergingDaoFlow(); //emerging user

// next create emerging oracle to save carbonOracle did to ./constants.ts
// emergingOraclesFlow(); //emerging user
emergingOraclesFlow(); //emerging user

// next create emerging protocols and save cookstoveAssetProtocol to ./constants.ts
// emergingProtocolsFlow(); //emerging user
emergingProtocolsFlow(); //emerging user

// next create daos and oracles and save prospectOracle did to ./constants.ts
// propectFlow(); //prospect user
propectFlow(); //prospect user

// next create ecs daos and save ecsDao did to ./constants.ts
// ecsDaoFlow(); //ecs user
ecsDaoFlow(); //ecs user
// next create ecs owned assetCollection etc and save assetCollectionDid did to ./constants.ts
// ecsFlow(); //ecs user
ecsFlow(); //ecs user
// Will issue device creds and claims etc
// send extra tokens to ecs user to have enough for gas fees to create all entities
// sendTokens(5);
sendTokens(5);

// next create emerging protocols and save carbonAsset to ./constants.ts
// emergingAssetsFlow(); //emerging user
emergingAssetsFlow(); //emerging user

// next create cookstoves
// cookstovesFlowDevnet(); //ecs user
cookstovesFlowDevnet(); //ecs user
// cookstovesFlow(); //ecs user, only for testnet and main net

// custom test for web3 storage uploading
Expand Down
Binary file modified assets/contracts/custom/wasmswap.wasm
Binary file not shown.
Loading

0 comments on commit 98c5dd2

Please sign in to comment.