Skip to content

Commit

Permalink
Merge pull request #46 from Splyce-Finance/integration-tests
Browse files Browse the repository at this point in the history
Integration tests: Roles and Permissions test suite - success tests
  • Loading branch information
vito-kovalione authored Dec 6, 2024
2 parents 3e39aaa + e0e5bea commit a62d3ec
Show file tree
Hide file tree
Showing 4 changed files with 1,305 additions and 39 deletions.
112 changes: 102 additions & 10 deletions tests/integration/setups/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export const vaultProgram = workspace.TokenizedVault as Program<TokenizedVault>;
export const strategyProgram = workspace.Strategy as Program<Strategy>;
export const accountantProgram = workspace.Accountant as Program<Accountant>;

export const TOKEN_METADATA_PROGRAM_ID = new anchor.web3.PublicKey(
"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
);
export const METADATA_SEED = "metadata";

export async function mochaGlobalSetup() {
console.log("-------Global Setup Started-------");
configOwner = anchor.web3.Keypair.generate();
Expand Down Expand Up @@ -50,14 +55,15 @@ export async function mochaGlobalSetup() {
accessControlProgram.programId
)[0];

const configOwnerRolesAdminRole = anchor.web3.PublicKey.findProgramAddressSync(
[
Buffer.from("user_role"),
configOwner.publicKey.toBuffer(),
ROLES_BUFFER.ROLES_ADMIN,
],
accessControlProgram.programId
)[0];
const configOwnerRolesAdminRole =
anchor.web3.PublicKey.findProgramAddressSync(
[
Buffer.from("user_role"),
configOwner.publicKey.toBuffer(),
ROLES_BUFFER.ROLES_ADMIN,
],
accessControlProgram.programId
)[0];

const configAccount = await accessControlProgram.account.config.fetch(config);

Expand All @@ -67,9 +73,14 @@ export async function mochaGlobalSetup() {
);

const configOwnerRolesAdminRoleAccount =
await accessControlProgram.account.userRole.fetch(configOwnerRolesAdminRole);
await accessControlProgram.account.userRole.fetch(
configOwnerRolesAdminRole
);

assert.equal(configAccount.owner.toString(), configOwner.publicKey.toString());
assert.equal(
configAccount.owner.toString(),
configOwner.publicKey.toString()
);
assert.equal(
Number(roleManageRolesAdminRoleAccount.managerRoleId),
Number(ROLES.ROLES_ADMIN)
Expand All @@ -79,5 +90,86 @@ export async function mochaGlobalSetup() {
console.log(
"Access Control program and Super Admin initialized successfully"
);

await accessControlProgram.methods
.setRoleManager(ROLES.VAULTS_ADMIN, ROLES.ROLES_ADMIN)
.accounts({
signer: configOwner.publicKey,
})
.signers([configOwner])
.rpc();

await accessControlProgram.methods
.setRoleManager(ROLES.STRATEGIES_MANAGER, ROLES.ROLES_ADMIN)
.accounts({
signer: configOwner.publicKey,
})
.signers([configOwner])
.rpc();

await accessControlProgram.methods
.setRoleManager(ROLES.ACCOUNTANT_ADMIN, ROLES.ROLES_ADMIN)
.accounts({
signer: configOwner.publicKey,
})
.signers([configOwner])
.rpc();

await accessControlProgram.methods
.setRoleManager(ROLES.REPORTING_MANAGER, ROLES.ROLES_ADMIN)
.accounts({
signer: configOwner.publicKey,
})
.signers([configOwner])
.rpc();

await accessControlProgram.methods
.setRoleManager(ROLES.KYC_PROVIDER, ROLES.ROLES_ADMIN)
.accounts({
signer: configOwner.publicKey,
})
.signers([configOwner])
.rpc();

await accessControlProgram.methods
.setRoleManager(ROLES.KYC_VERIFIED, ROLES.KYC_PROVIDER)
.accounts({
signer: configOwner.publicKey,
})
.signers([configOwner])
.rpc();

console.log("Setting role managers for all roles successfully");

await vaultProgram.methods
.initialize()
.accounts({
admin: configOwner.publicKey,
})
.signers([configOwner])
.rpc();

console.log("Vault program initialized successfully");

await strategyProgram.methods
.initialize()
.accounts({
admin: configOwner.publicKey,
})
.signers([configOwner])
.rpc();

console.log("Strategy program initialized successfully");

await accountantProgram.methods
.initialize()
.accounts({
admin: configOwner.publicKey,
})
.signers([configOwner])
.rpc();

console.log("Accountant program initalized successfully");

console.log("-------Global Setup Finished-------");
}
Loading

0 comments on commit a62d3ec

Please sign in to comment.