Skip to content

Commit

Permalink
fix: add txBodyBytes to custom client
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Ixo committed Jun 15, 2023
1 parent 007305a commit 9deeabc
Show file tree
Hide file tree
Showing 16 changed files with 240 additions and 162 deletions.
185 changes: 94 additions & 91 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 @@ -305,7 +311,7 @@ export const supamotoClaims = () =>
"starting batch " + (index + 1) + " of " + purchaseData.length
);
// add wait for ipfs rate limit
await timeout(1000 * 60);
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 * 20);

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
2 changes: 1 addition & 1 deletion __tests__/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const getFee = (trxLength = 1): StdFee => ({
amount: (trxLength * 10000).toString(),
},
],
gas: (trxLength * 50000).toString(),
gas: (trxLength * 500000).toString(),
// if wana do transactions using feegrant granter address
// granter: "ixo1n8yrmeatsk74dw0zs95ess9sgzptd6thgjgcj2",
});
2 changes: 2 additions & 0 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { bankBasic, authzBasic, sendTokens, govDeposit } from "./flows/cosmos";
import {
instantiateModulesProposals,
devnetProposals,
cwUploadProposal,
} from "./flows/instantiateProposals";
import { tokenBasic, supamotoTokens } from "./flows/tokens";
import { daoCore, wasmBasic } from "./flows/cosmwasm";
Expand Down Expand Up @@ -52,6 +53,7 @@ generateBlockchainTestUsers();
// authzBasic();
// wasmBasic();
// daoCore();
// cwUploadProposal();
// quickQueries();

// ------------------------------------------
Expand Down
13 changes: 0 additions & 13 deletions __tests__/modules/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,6 @@ export const GrantEntityAccountAuthz = async (
})
).finish(),
},
// authorization: {
// typeUrl: "/cosmos.bank.v1beta1.SendAuthorization",
// value: cosmos.bank.v1beta1.SendAuthorization.encode(
// cosmos.bank.v1beta1.SendAuthorization.fromPartial({
// spendLimit: [
// cosmos.base.v1beta1.Coin.fromPartial({
// amount: "10000000",
// denom: "uixo",
// }),
// ],
// })
// ).finish(),
// },
expiration: utils.proto.toTimestamp(addDays(new Date(), 365)),
}),
}),
Expand Down
6 changes: 3 additions & 3 deletions __tests__/setup/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const CarbonCredentialsWorkerUrl =
// };

// export const EcsCredentialsWorkerUrl =
// "https://ecs.credentials.tesnet.ixo.earth/";
// "https://ecs.credentials.testnet.ixo.earth/";
// export const ProspectCredentialsWorkerUrl =
// "https://prospect.credentials.tesnet.ixo.earth/";
// "https://prospect.credentials.testnet.ixo.earth/";
// export const CarbonCredentialsWorkerUrl =
// "https://carbon.credentials.tesnet.ixo.earth/";
// "https://carbon.credentials.testnet.ixo.earth/";
Loading

0 comments on commit 9deeabc

Please sign in to comment.