Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhargavamacha committed Aug 22, 2024
1 parent c4daf27 commit 65b4f14
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
2 changes: 1 addition & 1 deletion clients/rwa-token-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dist"
],
"scripts": {
"test": "vitest run --testTimeout=240000",
"test": "vitest run --testTimeout=240000",
"lint": "eslint . --ext .ts",
"build": "tsc"
},
Expand Down
45 changes: 28 additions & 17 deletions clients/rwa-token-sdk/tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,31 @@ describe("e2e tests", async () => {
const setupUserIxs = await getSetupUserIxs({
assetMint: mint,
payer: setup.payer.toString(),
owner: setup.authority.toString(),
owner: setup.user1.toString(),
signer: setup.authority.toString(),
level: 255
level: 1,
}, rwaClient.provider);
const setupUser2Ixs = await getSetupUserIxs({
assetMint: mint,
payer: setup.payer.toString(),
owner: setup.user2.toString(),
signer: setup.authority.toString(),
level: 1,
}, rwaClient.provider);
const txnId = await sendAndConfirmTransaction(
rwaClient.provider.connection,
new Transaction().add(...setupIx.ixs).add(...setupUserIxs.ixs),
[setup.payerKp, setup.authorityKp, ...setupIx.signers, ...setupUserIxs.signers]
);
await sendAndConfirmTransaction(
rwaClient.provider.connection,
new Transaction().add(...setupUser2Ixs.ixs),
[setup.payerKp, setup.authorityKp, ...setupUser2Ixs.signers]
);
expect(txnId).toBeTruthy();
const trackerAccount = await getTrackerAccount(
mint,
setup.authority.toString(),
setup.user1.toString(),
rwaClient.provider
);
expect(trackerAccount).toBeTruthy();
Expand Down Expand Up @@ -163,7 +175,7 @@ describe("e2e tests", async () => {
},
policyType: {
transactionAmountLimit: {
limit: new BN(100),
limit: new BN(10000),
},
},
};
Expand Down Expand Up @@ -232,14 +244,15 @@ describe("e2e tests", async () => {
const issueArgs: IssueTokenArgs = {
authority: setup.authority.toString(),
payer: setup.payer.toString(),
owner: setup.authority.toString(),
owner: setup.user1.toString(),
assetMint: mint,
amount: 1000000,
};
const issueIx = await rwaClient.assetController.issueTokenIxns(issueArgs);
const issue2Ix = await rwaClient.assetController.issueTokenIxns({...issueArgs, owner: setup.authority.toString(), createTa: true });
const txnId = await sendAndConfirmTransaction(
rwaClient.provider.connection,
new Transaction().add(...issueIx),
new Transaction().add(...issueIx).add(...issue2Ix),
[setup.payerKp, setup.authorityKp]
);
expect(txnId).toBeTruthy();
Expand All @@ -249,15 +262,15 @@ describe("e2e tests", async () => {
const voidArgs: VoidTokensArgs = {
payer: setup.payer.toString(),
amount: 100,
owner: setup.authority.toString(),
owner: setup.user1.toString(),
assetMint: mint,
authority: setup.authority.toString(),
authority: setup.user1.toString(),
};
const voidIx = await rwaClient.assetController.voidTokenIxns(voidArgs);
const txnId = await sendAndConfirmTransaction(
rwaClient.provider.connection,
new Transaction().add(voidIx),
[setup.payerKp, setup.authorityKp]
[setup.payerKp, setup.user1Kp]
);
expect(txnId).toBeTruthy();
});
Expand All @@ -266,7 +279,7 @@ describe("e2e tests", async () => {
const revokeIx = await getRevokeTokensIx({
authority: setup.authority.toString(),
payer: setup.payer.toString(),
owner: setup.authority.toString(),
owner: setup.user1.toString(),
assetMint: mint,
amount: 100,
}, rwaClient.provider);
Expand All @@ -282,7 +295,7 @@ describe("e2e tests", async () => {
const freezeIx = await getFreezeTokenIx({
authority: setup.authority.toString(),
payer: setup.payer.toString(),
owner: setup.authority.toString(),
owner: setup.user1.toString(),
assetMint: mint,
}, rwaClient.provider);
const txnId = await sendAndConfirmTransaction(
Expand All @@ -295,7 +308,7 @@ describe("e2e tests", async () => {
const thawIx = await getThawTokenIx({
authority: setup.authority.toString(),
payer: setup.payer.toString(),
owner: setup.authority.toString(),
owner: setup.user1.toString(),
assetMint: mint,
}, rwaClient.provider);
const txnId2 = await sendAndConfirmTransaction(
Expand All @@ -313,7 +326,6 @@ describe("e2e tests", async () => {
uri: "newUri",
type: { tax: {} },
payer: setup.payer.toString(),
owner: setup.authority.toString(),
assetMint: mint,
authority: setup.authority.toString(),
signer: setup.authority.toString(),
Expand Down Expand Up @@ -346,19 +358,18 @@ describe("e2e tests", async () => {

test("transfer tokens", async () => {
const transferArgs: TransferTokensArgs = {
from: setup.authority.toString(),
to: setup.user1.toString(),
from: setup.user1.toString(),
to: setup.user2.toString(),
assetMint: mint,
amount: 2000,
decimals,
createTa: true,
};

const transferIxs = await rwaClient.assetController.transfer(transferArgs);
const txnId = await sendAndConfirmTransaction(
rwaClient.provider.connection,
new Transaction().add(...transferIxs),
[setup.authorityKp]
[setup.user1Kp]
);
expect(txnId).toBeTruthy();
});
Expand Down
19 changes: 11 additions & 8 deletions programs/asset_controller/src/instructions/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ pub fn handler(ctx: Context<ExecuteTransferHook>, amount: u64) -> Result<()> {
&identity_registry::id(),
)?;

let levels = if let Ok(identity_account) =
IdentityAccount::deserialize(&mut &ctx.accounts.identity_account.data.borrow()[8..])
{
identity_account.levels
let levels = if !ctx.accounts.identity_account.data_is_empty() {
IdentityAccount::deserialize(&mut &ctx.accounts.identity_account.data.borrow()[8..])?.levels
} else {
vec![NO_IDENTITY_LEVEL]
};
Expand All @@ -128,11 +126,16 @@ pub fn handler(ctx: Context<ExecuteTransferHook>, amount: u64) -> Result<()> {
return Ok(());
}

let tracker_account: &mut Option<TrackerAccount> =
&mut TrackerAccount::deserialize(&mut &ctx.accounts.tracker_account.data.borrow()[8..])
.ok();
let mut tracker_account: Option<TrackerAccount> =
if ctx.accounts.tracker_account.data_is_empty() {
None
} else {
Some(TrackerAccount::deserialize(
&mut &ctx.accounts.tracker_account.data.borrow()[8..],
)?)
};

let transfers = if let Some(tracker_account) = tracker_account {
let transfers = if let Some(tracker_account) = tracker_account.clone() {
tracker_account.transfers.clone()
} else {
vec![]
Expand Down

0 comments on commit 65b4f14

Please sign in to comment.