Skip to content

Commit

Permalink
Merge pull request #20 from ixofoundation/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Michael-Ixo authored Mar 7, 2023
2 parents 0e6d189 + 4da9cb6 commit 4d95b9a
Show file tree
Hide file tree
Showing 63 changed files with 4,173 additions and 2,273 deletions.
17 changes: 16 additions & 1 deletion __tests__/flows/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@ export const authzBasic = () =>
return res;
});

// quick helper to send funds to an address
// testMsg("test Bank Send", async () => {
// const res = await Cosmos.BankSendTrx(
// 1000000000,
// WalletUsers.tester,
// undefined,
// "ixo1syjk0qh59vxz3zk776m5vrzvyv4nwpvh57yps2"
// );
// console.log(res);
// return res;
// });

testMsg("test Exec Send", async () => {
const res = await Authz.MsgExecSend();
const res = await Authz.MsgExecSend(
1000000,
"ixo1syjk0qh59vxz3zk776m5vrzvyv4nwpvh57yps2"
);
console.log(res);
return res;
});
Expand Down
32 changes: 27 additions & 5 deletions __tests__/flows/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,42 @@ import * as Entity from "../modules/Entity";

export const enititiesBasic = () =>
describe("Testing the entities module", () => {
let assetDid: string;
let entityDid = "did:ixo:entity:eaff254f2fc62aefca0d831bc7361c14";
testMsg("/ixo.entity.v1beta1.MsgCreateEntity asset", async () => {
const res = await Entity.CreateEntity();
assetDid = utils.common.getValueFromEvents(res, "wasm", "token_id");
console.log({ assetDid });
entityDid = utils.common.getValueFromEvents(res, "wasm", "token_id");
console.log({ entityDid });
return res;
});

// testMsg("/ixo.entity.v1beta1.MsgUpdateEntityVerified", () =>
// Entity.UpdateEntityVerified(undefined, assetDid)
// Entity.UpdateEntityVerified(undefined, entityDid)
// );

// testMsg("/ixo.entity.v1beta1.MsgTransferEntity", () =>
// Entity.TransferEntity(undefined, assetDid)
// Entity.TransferEntity(undefined, entityDid)
// );

// testMsg("/ixo.entity.v1beta1.MsgUpdateEntity", () => Entity.UpdateEntity());

let accountAddress = "ixo1syjk0qh59vxz3zk776m5vrzvyv4nwpvh57yps2";
let name = "name";
testMsg("/ixo.entity.v1beta1.MsgCreateEntityAccount", async () => {
const res = await Entity.CreateEntityAccount(entityDid, name);
accountAddress = utils.common.getValueFromEvents(
res,
"ixo.entity.v1beta1.EntityAccountCreatedEvent",
"account_address"
);
console.log({ accountAddress });
return res;
});

testMsg("/ixo.entity.v1beta1.MsgGrantEntityAccountAuthz", async () => {
const res = await Entity.GrantEntityAccountAuthz(entityDid, name);
console.log(res);
return res;
});
});

export const supamotoFlow = () =>
Expand Down
110 changes: 69 additions & 41 deletions __tests__/flows/quickQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,44 +88,52 @@ export const quickQueries = () =>
// expect(res).toBeTruthy();
// });

test("query claim collections list", async () => {
const res = await queryClient.ixo.claims.v1beta1.collectionList();
console.log(res.collections);
expect(res).toBeTruthy();
});

test("query claims list", async () => {
const res = await queryClient.ixo.claims.v1beta1.claimList();
console.log(res.claims);
expect(res).toBeTruthy();
});

test("query dispute list", async () => {
const res = await queryClient.ixo.claims.v1beta1.disputeList();
console.log(res.disputes);
expect(res).toBeTruthy();
});

test("query grants by grantee", async () => {
const user = (await getUser(WalletUsers.alice).getAccounts())[0].address;
const res = await queryClient.cosmos.authz.v1beta1.granteeGrants({
grantee: user,
});
if (res.grants.length > 0) {
console.log(
res.grants.map((g) => {
g.expiration = g.expiration?.seconds as any;
return g;
})
);
console.log(
res.grants.map(
(g) => createRegistry().decode(g.authorization!).constraints
)
);
}
expect(res).toBeTruthy();
});
// test("query claim collections list", async () => {
// const res = await queryClient.ixo.claims.v1beta1.collectionList();
// console.log(res.collections);
// expect(res).toBeTruthy();
// });

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

// test("query dispute list", async () => {
// const res = await queryClient.ixo.claims.v1beta1.disputeList();
// console.log(res.disputes);
// expect(res).toBeTruthy();
// });

// test("query entity list", async () => {
// const res = await queryClient.ixo.entity.v1beta1.entityList();
// console.log(res.entities);
// console.log(res.entities.map((e) => e.accounts));
// expect(res).toBeTruthy();
// });

// test("query grants by grantee", async () => {
// const user = (await getUser(WalletUsers.alice).getAccounts())[0].address;
// const res = await queryClient.cosmos.authz.v1beta1.granteeGrants({
// grantee: user,
// });
// if (res.grants.length > 0) {
// console.log(
// res.grants.map((g) => {
// g.expiration = g.expiration?.seconds as any;
// return g;
// })
// );
// console.log(
// res.grants.map((g) => {
// const auth = createRegistry().decode(g.authorization!);
// return auth.constraints || auth;
// })
// );
// }
// expect(res).toBeTruthy();
// });

// test("query grants by granter", async () => {
// const user = (await getUser(WalletUsers.tester).getAccounts())[0].address;
Expand All @@ -134,9 +142,12 @@ export const quickQueries = () =>
// });
// console.log(res.grants);
// if (res.grants.length > 0)
// console.log(
// res.grants.map((g) => createRegistry().decode(g.authorization!))
// );
// console.log(
// res.grants.map((g) => {
// const auth = createRegistry().decode(g.authorization!);
// return auth.constraints || auth;
// })
// );
// expect(res).toBeTruthy();
// });

Expand All @@ -157,4 +168,21 @@ export const quickQueries = () =>
// );
// expect(res).toBeTruthy();
// });

// test("query iid doc", async () => {
// const did: string =
// "did:x:zQ3shUQYdonbR4CaaWBmfYMHND7KEXY3tEStFndNGWp4njQ54";
// // const did = getUser(WalletUsers.tester).did;
// const res = await queryClient.ixo.iid.v1beta1.iidDocument({
// id: did,
// });
// console.log(res.iidDocument);
// expect(res).toBeTruthy();
// });

// test("Query module params", async () => {
// const res = await queryClient.ixo.entity.v1beta1.params();
// console.log(res.params);
// expect(res).toBeTruthy();
// });
});
2 changes: 1 addition & 1 deletion __tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ generateBlockchainTestUsers();
// authzBasic();
// wasmBasic();
// daoCore();
// quickQueries();
quickQueries();
10 changes: 6 additions & 4 deletions __tests__/modules/Authz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ export const MsgGrantSend = async (
};

export const MsgExecSend = async (
amount = "1000",
amount = 1000,
granterAddress?: string,
granter = WalletUsers.tester,
grantee = WalletUsers.alice
) => {
const client = await createClient(getUser(grantee));

const granterAddress = (await getUser(granter).getAccounts())[0].address;
const granterrAddress =
granterAddress || (await getUser(granter).getAccounts())[0].address;
const granteeAddress = (await getUser(grantee).getAccounts())[0].address;

const message = {
Expand All @@ -70,11 +72,11 @@ export const MsgExecSend = async (
cosmos.bank.v1beta1.MsgSend.fromPartial({
amount: [
cosmos.base.v1beta1.Coin.fromPartial({
amount,
amount: amount.toString(),
denom: "uixo",
}),
],
fromAddress: granterAddress,
fromAddress: granterrAddress,
toAddress: granteeAddress,
})
).finish(),
Expand Down
6 changes: 4 additions & 2 deletions __tests__/modules/Cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import Long from "long";
export const BankSendTrx = async (
amount = Math.pow(10, 6),
fromUser = WalletUsers.random,
toUser = WalletUsers.tester
toUser = WalletUsers.tester,
toAddresss?: string
) => {
const client = await createClient(getUser(fromUser));

const fromAddress = (await getUser(fromUser).getAccounts())[0].address;
const toAddress = (await getUser(toUser).getAccounts())[0].address;
const toAddress =
toAddresss || (await getUser(toUser).getAccounts())[0].address;

const message = {
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
Expand Down
81 changes: 80 additions & 1 deletion __tests__/modules/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import {
createAgentIidContext,
createIidVerificationMethods,
} from "../../src/messages/iid";
import { createClient, getUser, ixo, queryClient } from "../helpers/common";
import {
addDays,
cosmos,
createClient,
getUser,
ixo,
queryClient,
utils,
} from "../helpers/common";
import { fee, keyType, WalletUsers } from "../helpers/constants";

export const CreateEntity = async (
Expand Down Expand Up @@ -400,3 +408,74 @@ export const UpdateEntityVerified = async (
const response = await client.signAndBroadcast(myAddress, [message], fee);
return response;
};

export const CreateEntityAccount = async (
entityDid: string,
name = "name",
signer: WalletUsers = WalletUsers.tester
) => {
const client = await createClient(getUser(signer));

const tester = (await getUser(signer).getAccounts())[0].address;

const message = {
typeUrl: "/ixo.entity.v1beta1.MsgCreateEntityAccount",
value: ixo.entity.v1beta1.MsgCreateEntityAccount.fromPartial({
id: entityDid,
ownerAddress: tester,
name,
}),
};

const response = await client.signAndBroadcast(tester, [message], fee);
return response;
};

export const GrantEntityAccountAuthz = async (
entityDid: string,
name = "name",
grantee: WalletUsers = WalletUsers.alice,
signer: WalletUsers = WalletUsers.tester
) => {
const client = await createClient(getUser(signer));

const tester = (await getUser(signer).getAccounts())[0].address;
const granteeAddress = (await getUser(grantee).getAccounts())[0].address;

const message = {
typeUrl: "/ixo.entity.v1beta1.MsgGrantEntityAccountAuthz",
value: ixo.entity.v1beta1.MsgGrantEntityAccountAuthz.fromPartial({
id: entityDid,
ownerAddress: tester,
name,
granteeAddress,
grant: cosmos.authz.v1beta1.Grant.fromPartial({
authorization: {
typeUrl: "/cosmos.authz.v1beta1.GenericAuthorization",
value: cosmos.authz.v1beta1.GenericAuthorization.encode(
cosmos.authz.v1beta1.GenericAuthorization.fromPartial({
msg: "/cosmos.gov.v1beta1.MsgVote",
})
).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)),
}),
}),
};

const response = await client.signAndBroadcast(tester, [message], fee);
return response;
};
2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

Loading

0 comments on commit 4d95b9a

Please sign in to comment.