Skip to content

Commit

Permalink
add more tests and update current ones (#56)
Browse files Browse the repository at this point in the history
* allow transfers for non policy attached assets and update tests

* use self hosted

* add more tests
  • Loading branch information
Bhargavamacha authored May 20, 2024
1 parent 85a652f commit cc2d716
Show file tree
Hide file tree
Showing 14 changed files with 715 additions and 74 deletions.
4 changes: 2 additions & 2 deletions clients/rwa-token-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "RWA Token SDK for the development of permissioned tokens on SVM blockchains.",
"homepage": "https://github.com/bridgesplit/rwa-token#readme",
"scripts": {
"test": "vitest run --testTimeout=120000",
"test": "vitest run --testTimeout=120000 ./tests/tracker.test.ts",
"lint": "eslint . --ext .ts"
},
"repository": {
Expand All @@ -30,7 +30,7 @@
"eslint-config-xo-typescript": "^3.0.0",
"typedoc": "^0.25.13",
"typescript": ">=5.0.0",
"vitest": "^1.5.0"
"vitest": "^1.5.2"
},
"author": "Standard Labs, Inc.",
"contributors": [
Expand Down
5 changes: 0 additions & 5 deletions clients/rwa-token-sdk/src/asset-controller/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
import {
type CommonArgs,
type IxReturn,
parseRemainingAccounts,
} from "../utils";
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
Expand Down Expand Up @@ -150,10 +149,7 @@ export type TransferTokensArgs = {
from: string;
to: string;
amount: number;
authority: string;
decimals: number;
/** Optional parameter for transfer controls (policies) and privacy (identity). */
remainingAccounts?: string[];
} & CommonArgs;

/**
Expand Down Expand Up @@ -216,7 +212,6 @@ export async function getTransferTokensIx(
isSigner: false,
},
];
remainingAccounts.push(...parseRemainingAccounts(args.remainingAccounts));
const ix = createTransferCheckedInstruction(
getAssociatedTokenAddressSync(
new PublicKey(args.assetMint),
Expand Down
1 change: 0 additions & 1 deletion clients/rwa-token-sdk/src/policy-engine/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export async function getCreatePolicyEngineIx(
/** Represents the arguments required to attach a policy to an asset. */
export type AttachPolicyArgs = {
authority: string;
owner: string;
assetMint: string;
payer: string;
identityFilter: IdentityFilter;
Expand Down
19 changes: 1 addition & 18 deletions clients/rwa-token-sdk/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AnchorProvider } from "@coral-xyz/anchor";
import {
Connection, type Keypair, PublicKey, type TransactionInstruction,
Connection, type Keypair, type TransactionInstruction,
} from "@solana/web3.js";

/** Retrieves the provider used for interacting with the Solana blockchain.
Expand All @@ -21,23 +21,6 @@ export type IxReturn = {
signers: Keypair[];
};

/**
* Parses remaining accounts received from a transaction instruction.
* @param remainingAccounts - An optional array of strings representing account public keys.
* @returns An array of parsed account objects.
*/
export function parseRemainingAccounts(remainingAccounts?: string[]) {
if (!remainingAccounts) {
return [];
}

return remainingAccounts.map(account => ({
pubkey: new PublicKey(account),
isWritable: false,
isSigner: false,
}));
}

/** Common args for all RWA instructions */
export type CommonArgs = {
assetMint: string;
Expand Down
8 changes: 2 additions & 6 deletions clients/rwa-token-sdk/tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { expect, test, describe } from "vitest";
import { type Config } from "../src/classes/types";
import { RwaClient } from "../src/classes";

describe("e2e tests", () => {
describe("e2e tests", async () => {
let rwaClient: RwaClient;
let mint: string;
const setup = setupTests();
const setup = await setupTests();

const decimals = 2;
const remainingAccounts: string[] = [];
Expand Down Expand Up @@ -138,7 +138,6 @@ describe("e2e tests", () => {
test("create identity approval policy", async () => {
const policyArgs: AttachPolicyArgs = {
authority: setup.authority.toString(),
owner: setup.authority.toString(),
assetMint: mint,
payer: setup.payer.toString(),
identityFilter: {
Expand All @@ -163,7 +162,6 @@ describe("e2e tests", () => {
test("attach transaction amount limit policy", async () => {
const policyArgs: AttachPolicyArgs = {
payer: setup.payer.toString(),
owner: setup.authority.toString(),
assetMint: mint,
authority: setup.authority.toString(),
identityFilter: {
Expand All @@ -189,7 +187,6 @@ describe("e2e tests", () => {
test("attach transaction amount velocity policy", async () => {
const policyArgs: AttachPolicyArgs = {
payer: setup.payer.toString(),
owner: setup.authority.toString(),
assetMint: mint,
authority: setup.authority.toString(),
identityFilter: {
Expand All @@ -215,7 +212,6 @@ describe("e2e tests", () => {
test("attach transaction count velocity policy", async () => {
const policyArgs: AttachPolicyArgs = {
payer: setup.payer.toString(),
owner: setup.authority.toString(),
assetMint: mint,
authority: setup.authority.toString(),
identityFilter: {
Expand Down
Loading

0 comments on commit cc2d716

Please sign in to comment.