Skip to content

Commit

Permalink
Merge pull request #40 from ixofoundation/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Michael-Ixo authored Jun 15, 2023
2 parents 3fb2c42 + 9deeabc commit f75bab6
Show file tree
Hide file tree
Showing 22 changed files with 452 additions and 206 deletions.
213 changes: 108 additions & 105 deletions __tests__/flows/claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ import {
} from "../setup/constants";
import { chainNetwork } from "../index.spec";
import axios from "axios";
import axiosRetry from "axios-retry";
import { cookstoveIds } from "../setup/supamoto/stoves";
import { assertIsDeliverTxSuccess } from "@cosmjs/stargate";

axiosRetry(axios, {
retries: 3,
retryDelay: () => 1000,
});

export const claimsBasic = () =>
describe("Testing the Claims module", () => {
// Create protocol
Expand Down Expand Up @@ -144,20 +150,20 @@ 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
Expand Down Expand Up @@ -305,7 +311,7 @@ export const supamotoClaims = () =>
"starting batch " + (index + 1) + " of " + purchaseData.length
);
// add wait for ipfs rate limit
await timeout(1000 * 50);
if (index) await timeout(1000 * 20);

// create fuelPurchase claims for each purchase
const fpClaims = await axios.post(
Expand Down Expand Up @@ -340,8 +346,8 @@ export const supamotoClaims = () =>
fpClaimIds.length + " FuelPurchase claims successfully created"
);

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

// save fuelPurchase claim ids per purchase
stovePurchases.forEach((ps: any[], i) => {
Expand Down Expand Up @@ -395,94 +401,91 @@ export const supamotoClaims = () =>
});

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

// create VER evaluations for cer claim in batches of 30 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),
27
);
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
await timeout(1000 * 15);

const verEvaluations = await axios.post(
CarbonCredentialsWorkerUrl + "claims/certify",
{
type: "VER",
collectionId: "1",
storage: "ipfs",
evaluationCreds: evaluations,
},
{
headers: {
Authorization: process.env.CARBON_CREDENTIAL_WORKER_AUTH,
},
}
);
assertIsDeliverTxSuccess(verEvaluations.data);
}
console.log("VER claims successfully created");

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

// mint tokens for each cer claim with ver evaluation
const mintTokens = await axios.post(
CarbonCredentialsWorkerUrl + "tokens/mintFromVER",
{
name: "CARBON",
claimIds: stovePurchases
.flat(1)
.map((p: any) => p.cerClaimId)
.filter((d) => !!d),
},
{
headers: {
Authorization: process.env.CARBON_CREDENTIAL_WORKER_AUTH,
},
}
);
assertIsDeliverTxSuccess(mintTokens.data);
console.log("Tokens successfully minted");

// 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
stovePurchasesAll = stovePurchasesAll.concat(stovePurchases);
Expand Down
25 changes: 25 additions & 0 deletions __tests__/flows/instantiateProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,28 @@ export const devnetProposals = () =>
}
);
});

// ------------------------------------------------------------
// flow to upload a cw smart contract, then need to vote on it
// ------------------------------------------------------------
export const cwUploadProposal = () =>
describe("Testing the gov module", () => {
testMsg(
"/cosmos.gov.v1beta1.MsgSubmitProposal store wasm contract",
async () => {
const name = "wasmswap";
const res = await Cosmos.MsgSubmitProposalStoreCW(`custom ${name}`, [
"contracts",
"custom",
`${name}.wasm`,
]);
const proposalId = utils.common.getValueFromEvents(
res,
"submit_proposal",
"proposal_id"
);
console.log({ proposalId });
return res;
}
);
});
45 changes: 38 additions & 7 deletions __tests__/flows/quickQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,43 @@ export const quickQueries = () =>

// test("Query cosmos.tx.v1beta1.getTx", async () => {
// const res = await queryClient.cosmos.tx.v1beta1.getTx({
// hash: "059CE93CA191E3E097247A23537A3B326128BF0101A44B5B23F9CD93A9AA68F5",
// hash: "525F02F796360AE6B7407765FE679595EFB5053E352C18C276C0255D44290BF2",
// });
// console.log(res.tx);
// console.dir(res.tx, { depth: null });
// // console.dir(createRegistry().decode(res.tx!.body!.messages![0]), {
// // depth: null,
// // });
// expect(res).toBeTruthy();
// });

// test("Decode txBodyBytes", async () => {
// const txBodyBytes = [
// 10, 217, 1, 10, 46, 47, 105, 120, 111, 46, 101, 110, 116, 105, 116, 121,
// 46, 118, 49, 98, 101, 116, 97, 49, 46, 77, 115, 103, 71, 114, 97, 110,
// 116, 69, 110, 116, 105, 116, 121, 65, 99, 99, 111, 117, 110, 116, 65,
// 117, 116, 104, 122, 18, 166, 1, 10, 3, 100, 105, 100, 18, 5, 97, 100,
// 109, 105, 110, 26, 16, 105, 120, 111, 49, 120, 113, 119, 108, 104, 106,
// 120, 107, 50, 99, 54, 122, 34, 90, 10, 75, 10, 42, 47, 99, 111, 115,
// 109, 111, 115, 46, 97, 117, 116, 104, 122, 46, 118, 49, 98, 101, 116,
// 97, 49, 46, 71, 101, 110, 101, 114, 105, 99, 65, 117, 116, 104, 111,
// 114, 105, 122, 97, 116, 105, 111, 110, 18, 29, 10, 27, 47, 99, 111, 115,
// 109, 111, 115, 46, 103, 111, 118, 46, 118, 49, 98, 101, 116, 97, 49, 46,
// 77, 115, 103, 86, 111, 116, 101, 18, 11, 8, 208, 217, 170, 164, 6, 16,
// 128, 235, 147, 79, 42, 42, 105, 120, 111, 49, 121, 48, 100, 55, 119, 53,
// 120, 102, 106, 57, 97, 48, 112, 55, 121, 103, 112, 120, 48, 117, 119,
// 118, 121, 114, 110, 109, 109, 113, 106, 51, 102, 100, 52, 115, 118, 97,
// 55, 116,
// ];

// const txBody = TxBody.decode(txBodyBytes as any);
// console.dir(txBody.messages[0], { depth: null });

// const msg = createRegistry().decode(txBody.messages[0]);
// console.dir(msg, { depth: null });

// expect(true).toBeTruthy();
// });

// test("Query cosmos.tx.v1beta1.getTxsEvent", async () => {
// const res = await queryClient.cosmos.tx.v1beta1.getTxsEvent({
// events: [`tx.height=${15955}`],
Expand Down Expand Up @@ -246,13 +277,13 @@ export const quickQueries = () =>
// const res = await queryClient.cosmos.authz.v1beta1.grants({
// granter,
// grantee,
// msgTypeUrl: "/ixo.claims.v1beta1.MsgSubmitClaim",
// msgTypeUrl: "",
// });
// console.log(res.grants);
// if (res.grants.length > 0)
// console.log(
// res.grants.map((g) => createRegistry().decode(g.authorization!))
// );
// // if (res.grants.length > 0)
// // console.log(
// // res.grants.map((g) => createRegistry().decode(g.authorization!))
// // );
// expect(res).toBeTruthy();
// });

Expand Down
21 changes: 15 additions & 6 deletions __tests__/flows/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const supamotoTokens = () =>
let cap = 0; // no cap

let contractAddress1155 =
"ixo1nc5tatafv6eyq7llkr2gv50ff9e22mnf70qgjlv737ktmt4eswrqvg5w3c";
"ixo1q85duf4uqqn97j2y52pep65mukux3edypm7ns2upfgnrg6pnsj0sj2hv3e";
testMsg("/ixo.token.v1beta1.MsgCreateToken", async () => {
const res = await Token.CreateToken(
name,
Expand All @@ -162,11 +162,11 @@ export const supamotoTokens = () =>
});

// let index = "1";
// let amount = 2;
// let amount = 265;
// // Did of collection (supamotoEntitiesFlow protocolAssetDid)
// let collectionDid = "did:ixo:entity:61392c571ef644d54d77e4daf611bf89";
// let collectionDid = "did:ixo:entity:eb98bb2c92a62557b6c88c6f80e8d258";
// // Did of entity to map token to (supamotoEntitiesFlow first nft created)
// let nftDid = "did:ixo:entity:2f22535f8b179a51d77a0e302e68d35d"; //Cookstove
// let nftDid = "did:ixo:entity:75d738bbf9a61ec05acc16625d70a82c"; //Cookstove
// const getTokenData = (nftDidId: string) => [
// {
// uri: "https://media.makeameme.org/created/haha-you-were-a3866a4349.jpg",
Expand All @@ -177,7 +177,7 @@ export const supamotoTokens = () =>
// },
// ];

// let tokenId = "d89fc11cef9424891fdf9ae173f88a6e";
// let tokenId = "b38e39af5bafe82e4329e630b4439e08";
// testMsg("/ixo.token.v1beta1.MsgMintToken", async () => {
// const res = await Token.MintToken(contractAddress1155, [
// {
Expand All @@ -193,11 +193,20 @@ export const supamotoTokens = () =>
// return res;
// });

// testMsg("/ixo.token.v1beta1.MsgTransferToken", () =>
// Token.TransferToken([
// {
// id: tokenId,
// amount: 1,
// },
// ])
// );

// testMsg("/ixo.token.v1beta1.MsgCancelToken", () =>
// Token.CancelToken([
// {
// id: tokenId,
// amount: 1,
// amount: 2,
// },
// ])
// );
Expand Down
Loading

0 comments on commit f75bab6

Please sign in to comment.