Skip to content

Commit

Permalink
tests: adding setup flows
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Ixo committed Apr 4, 2023
1 parent f5d9697 commit 54c49a8
Show file tree
Hide file tree
Showing 38 changed files with 3,781 additions and 190 deletions.
5 changes: 2 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
RPC_URL=https://testnet.ixo.earth/rpc/
RPC_URL=https://impacthub-rpc.lavenderfive.com/
RPC_URL=http://localhost:26658/
RPC_URL=https://testnet.ixo.earth/rpc/ #https://impacthub-rpc.lavenderfive.com/ #http://localhost:26658/
# NEVER COMMIT MAINNET MNENOMICS!! Please be careful.
TESTER_MNEMONIC-"mango tattoo civil foam frog wheat venue rebuild cloth example alien taste"
IBC_FROM_MNEMONIC="mango tattoo civil foam frog wheat venue rebuild cloth example alien taste"
IBC_TO_ADDRESS=ixo1tumrhpa5tpegdcs2nhwzft8maprttz66pvntc9
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
{
trailingComma: 'none',
singleQuote: true,
printWidth: 80
printWidth: 120
}
]
}
Expand Down
10 changes: 6 additions & 4 deletions __tests__/flows/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import { WalletUsers } from "../helpers/constants";

export const bankBasic = () =>
describe("Testing the cosmos bank module", () => {
testMsg("/cosmos.bank.v1beta1.MsgSend", () =>
Cosmos.BankSendTrx(
testMsg("/cosmos.bank.v1beta1.MsgSend", async () => {
const res = await Cosmos.BankSendTrx(
undefined,
WalletUsers.tester,
WalletUsers.tester,
"secp",
"ed"
)
);
);
console.log(res);
return res;
});
});

export const authzBasic = () =>
Expand Down
158 changes: 80 additions & 78 deletions __tests__/flows/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const supamotoEntities = () =>

// Save supamoto credsPdf WEB3
let projectCertDoc =
"https://bafkreiefafy2u5df4l52yb7vvz32hxrxhcceyaq3z7xww2qlz2fp3ppeum.ipfs.w3s.link";
"bafkreiefafy2u5df4l52yb7vvz32hxrxhcceyaq3z7xww2qlz2fp3ppeum";
test("Saving projectCertDoc", async () => {
projectCertDoc = (
await customQueries.cellnode.uploadWeb3Doc(
Expand All @@ -136,14 +136,13 @@ export const supamotoEntities = () =>
undefined,
cellNodeNetwork
)
).url;
).cid;
console.log({ projectCertDoc });
expect(projectCertDoc).toBeTruthy();
});

// Save supamoto profile WEB3
let profile =
"https://bafkreib5ka542u2ousereo23hr77qfaohtn2inhkr436u74rqzsktefynm.ipfs.w3s.link";
let profile = "4kavdefz12wlefltwxr";
test("Saving profile", async () => {
const file = JSON.parse(
getFileFromPath(["documents", "test-supamoto-profile.jsonld"], "ascii")
Expand All @@ -152,85 +151,84 @@ export const supamotoEntities = () =>
file["logo"] = supaLogo;
let buff = Buffer.from(JSON.stringify(file));
profile = (
await customQueries.cellnode.uploadWeb3Doc(
utils.common.generateId(12),
await customQueries.cellnode.uploadPublicDoc(
"application/ld+json",
buff.toString("base64"),
undefined,
cellNodeNetwork
)
).url;
).key;
console.log({ profile });
expect(profile).toBeTruthy();
});

// Save supamoto creator CELLNODE
let creator = "4kavdefz12wlefltwxr";
test("Saving creator", async () => {
const tester = getUser();
const file = JSON.parse(
getFileFromPath(["documents", "test-supamoto-creator.jsonld"], "ascii")
);
file["issuer"] = tester.did;
file["credentialSubject"]["id"] = daoCredsIssuerDid;
file["credentialSubject"]["logo"] = ecsLogo;
let buff = Buffer.from(JSON.stringify(file));
creator = (
await customQueries.cellnode.uploadPublicDoc(
"application/ld+json",
buff.toString("base64"),
undefined,
cellNodeNetwork
)
).key;
console.log({ creator });
expect(creator).toBeTruthy();
});
// Save supamoto creator CELLNODE emerging cellnode
// let creator = "4kavdefz12wlefltwxr";
// test("Saving creator", async () => {
// const tester = getUser();
// const file = JSON.parse(
// getFileFromPath(["documents", "test-supamoto-creator.jsonld"], "ascii")
// );
// file["issuer"] = tester.did;
// file["credentialSubject"]["id"] = daoCredsIssuerDid;
// file["credentialSubject"]["logo"] = ecsLogo;
// let buff = Buffer.from(JSON.stringify(file));
// creator = (
// await customQueries.cellnode.uploadPublicDoc(
// "application/ld+json",
// buff.toString("base64"),
// undefined,
// cellNodeNetwork
// )
// ).key;
// console.log({ creator });
// expect(creator).toBeTruthy();
// });

// Save supamoto administrator CELLNODE
let administrator = "gm7528l8xd4lefltxcz";
test("Saving administrator", async () => {
const tester = getUser();
const file = JSON.parse(
getFileFromPath(
["documents", "test-supamoto-administrator.jsonld"],
"ascii"
)
);
file["issuer"] = tester.did;
file["credentialSubject"]["id"] = daoCredsIssuerDid;
file["credentialSubject"]["logo"] = ecsLogo;
let buff = Buffer.from(JSON.stringify(file));
administrator = (
await customQueries.cellnode.uploadPublicDoc(
"application/ld+json",
buff.toString("base64"),
undefined,
cellNodeNetwork
)
).key;
console.log({ administrator });
expect(administrator).toBeTruthy();
});
// let administrator = "gm7528l8xd4lefltxcz";
// test("Saving administrator", async () => {
// const tester = getUser();
// const file = JSON.parse(
// getFileFromPath(
// ["documents", "test-supamoto-administrator.jsonld"],
// "ascii"
// )
// );
// file["issuer"] = tester.did;
// file["credentialSubject"]["id"] = daoCredsIssuerDid;
// file["credentialSubject"]["logo"] = ecsLogo;
// let buff = Buffer.from(JSON.stringify(file));
// administrator = (
// await customQueries.cellnode.uploadPublicDoc(
// "application/ld+json",
// buff.toString("base64"),
// undefined,
// cellNodeNetwork
// )
// ).key;
// console.log({ administrator });
// expect(administrator).toBeTruthy();
// });

// Save supamoto page CELLNODE
let page = "zh211j0pb0llefltxre";
test("Saving page", async () => {
page = (
await customQueries.cellnode.uploadPublicDoc(
"application/json",
getFileFromPath(["documents", "test-supamoto-page.json"]),
undefined,
cellNodeNetwork
)
).key;
console.log({ page });
expect(page).toBeTruthy();
});
// let page = "zh211j0pb0llefltxre";
// test("Saving page", async () => {
// page = (
// await customQueries.cellnode.uploadPublicDoc(
// "application/json",
// getFileFromPath(["documents", "test-supamoto-page.json"]),
// undefined,
// cellNodeNetwork
// )
// ).key;
// console.log({ page });
// expect(page).toBeTruthy();
// });

// Save supamoto projectCreds WEB3
let projectCreds =
"https://bafkreih2oq64xhbgp7vyarcrgw6dcofms4zdmjqms6vnfx32vzwglj6nd4.ipfs.w3s.link";
"bafkreih2oq64xhbgp7vyarcrgw6dcofms4zdmjqms6vnfx32vzwglj6nd4";
test("Saving projectCert", async () => {
const file = JSON.parse(
getFileFromPath(
Expand All @@ -243,8 +241,8 @@ export const supamotoEntities = () =>
"credentialSubject"
]["project"]["linkedResources"].map((lr: any) => ({
...lr,
id: projectCertDoc,
proof: projectCertDoc.split(".")[0].split("/")[2],
id: `https://ipfs.io/ipfs/${projectCertDoc}`,
proof: projectCertDoc,
}));
let buff = Buffer.from(JSON.stringify(file));
projectCreds = (
Expand All @@ -255,7 +253,7 @@ export const supamotoEntities = () =>
undefined,
cellNodeNetwork
)
).url;
).cid;
console.log({ projectCreds });
expect(projectCreds).toBeTruthy();
});
Expand All @@ -275,9 +273,9 @@ export const supamotoEntities = () =>
expect(tags).toBeTruthy();
});

// Save supamoto tokenMetadata WEB3
// Save supamoto tokenMetadata WEB3 emerging account
let tokenMetadata =
"https://bafkreie7kbpppoizx7anxxufblfkdfmuy27mppuz2hq4a4uouudweb2sm4.ipfs.w3s.link";
"bafkreie7kbpppoizx7anxxufblfkdfmuy27mppuz2hq4a4uouudweb2sm4";
test("Saving tokenMetadata", async () => {
const file = JSON.parse(
getFileFromPath(
Expand All @@ -296,11 +294,12 @@ export const supamotoEntities = () =>
undefined,
cellNodeNetwork
)
).url;
).cid;
console.log({ tokenMetadata });
expect(tokenMetadata).toBeTruthy();
});

// TODO need protocol to add as template id
// Save supamoto claims CELLNODE
let claims = "gf9m2u5ds6tleflu4a8";
test("Saving claims", async () => {
Expand All @@ -316,6 +315,7 @@ export const supamotoEntities = () =>
expect(claims).toBeTruthy();
});

// TODO cookstove-asset-protocol
// Create a base Protocol entity
let protocolDid = "did:ixo:entity:065ba0b99948e2e8ff3228836dee423b";
testMsg("/ixo.entity.v1beta1.MsgCreateEntity protocol", async () => {
Expand All @@ -331,9 +331,9 @@ export const supamotoEntities = () =>
const res = await Entity.CreateEntityAssetSupamoto({
inheritEntityDid: protocolDid,
profile,
page,
creator,
administrator,
// page,
// creator,
// administrator,
tags,
claims,
tokenMetadata,
Expand Down Expand Up @@ -388,7 +388,9 @@ export const supamotoEntities = () =>
file["credentialSubject"]["id"] = (
file["credentialSubject"]["id"] as string
).replace("deviceId", id);
file["credentialSubject"]["certification"]["id"] = projectCertDoc;
file["credentialSubject"]["certification"][
"id"
] = `https://ipfs.io/ipfs/${projectCertDoc}`;
let buff = Buffer.from(JSON.stringify(file));
deviceCreds = (
await customQueries.cellnode.uploadWeb3Doc(
Expand All @@ -398,7 +400,7 @@ export const supamotoEntities = () =>
undefined,
cellNodeNetwork
)
).url;
).cid;

console.log({ deviceCreds });
if (!deviceCreds) throw new Error("error saving device creds file");
Expand Down
6 changes: 6 additions & 0 deletions __tests__/flows/quickQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ export const quickQueries = () =>
// expect(res).toBeTruthy();
// });

// test("query entity params", async () => {
// const res = await queryClient.ixo.entity.v1beta1.params();
// console.log(res.params);
// expect(res).toBeTruthy();
// });

// test("query entity by id", async () => {
// const res = await queryClient.ixo.entity.v1beta1.entity({
// id: "did:ixo:entity:eaff254f2fc62aefca0d831bc7361c14",
Expand Down
40 changes: 21 additions & 19 deletions __tests__/helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type wallet = {

export let wallets: { [key in WalletUsers]: wallet };

export const generateWallets = async () => {
export const generateWallets = async (log = true) => {
let generatedWallets = {};
for (const user of Object.values(WalletUsers)) {
const mnemonics = utils.mnemonic.generateMnemonic(24);
Expand All @@ -49,25 +49,27 @@ export const generateWallets = async () => {
}
wallets = generatedWallets as any;

// Logs wallet for tester to see account details for wallets
let walletLog = {};
for (const [user, wallet] of Object.entries(wallets)) {
const edAccount = (await wallet.ed.getAccounts())[0];
const secpAccount = (await wallet.secp.getAccounts())[0];
walletLog[user] = {
ed: {
did: wallet.ed.did,
address: edAccount.address,
publicKey: base58.encode(edAccount.pubkey),
},
secp: {
did: wallet.secp.did,
address: secpAccount.address,
publicKey: base58.encode(secpAccount.pubkey),
},
};
if (log) {
// Logs wallet for tester to see account details for wallets
let walletLog = {};
for (const [user, wallet] of Object.entries(wallets)) {
const edAccount = (await wallet.ed.getAccounts())[0];
const secpAccount = (await wallet.secp.getAccounts())[0];
walletLog[user] = {
ed: {
did: wallet.ed.did,
address: edAccount.address,
publicKey: base58.encode(edAccount.pubkey),
},
secp: {
did: wallet.secp.did,
address: secpAccount.address,
publicKey: base58.encode(secpAccount.pubkey),
},
};
}
console.log(walletLog);
}
console.log(walletLog);
};

export const generateNewWallet = async (
Expand Down
8 changes: 6 additions & 2 deletions __tests__/modules/CosmWasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export const WasmStoreTrx = async (
return response;
};

export const WasmInstantiateTrx = async (codeId: number, msg: string) => {
export const WasmInstantiateTrx = async (
codeId: number,
msg: string,
funds = 1
) => {
const client = await createClient();

const tester = getUser();
Expand All @@ -54,7 +58,7 @@ export const WasmInstantiateTrx = async (codeId: number, msg: string) => {
codeId: Long.fromNumber(codeId),
funds: [
cosmos.base.v1beta1.Coin.fromPartial({
amount: "1",
amount: String(funds),
denom: "uixo",
}),
],
Expand Down
Loading

0 comments on commit 54c49a8

Please sign in to comment.