Skip to content

Commit

Permalink
use runIf for describe instead of if/else
Browse files Browse the repository at this point in the history
  • Loading branch information
jnaulty committed Oct 30, 2024
1 parent 6eff9ee commit 5c071ba
Showing 1 changed file with 32 additions and 38 deletions.
70 changes: 32 additions & 38 deletions sdk/kms/tests/e2e-aws-kms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,41 @@ import { AwsKmsSigner } from '../src/aws/aws-kms-signer';

const { E2E_AWS_KMS_TEST_ENABLE } = process.env;

if (!E2E_AWS_KMS_TEST_ENABLE) {
describe.skip('Aws KMS Signer E2E testing', () => {
// Skip Tests -- not in E2E_CI_ENABLE Environment.
});
} else {
describe('Aws KMS signer E2E testing', () => {
let signer: AwsKmsSigner;
beforeAll(async () => {
const { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_KMS_KEY_ID } = process.env;

if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !AWS_REGION || !AWS_KMS_KEY_ID) {
throw new Error('Missing one or more required environment variables.');
}

signer = await AwsKmsSigner.fromCredentials(AWS_KMS_KEY_ID, {
region: AWS_REGION,
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
});
describe.runIf(E2E_AWS_KMS_TEST_ENABLE)('Aws KMS signer E2E testing', () => {
let signer: AwsKmsSigner;
beforeAll(async () => {
const { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_KMS_KEY_ID } = process.env;

if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !AWS_REGION || !AWS_KMS_KEY_ID) {
throw new Error('Missing one or more required environment variables.');
}

signer = await AwsKmsSigner.fromCredentials(AWS_KMS_KEY_ID, {
region: AWS_REGION,
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
});
});

it('should retrieve the correct sui address', async () => {
// Get the public key
const publicKey = signer.getPublicKey();
expect(publicKey.toSuiAddress()).toEqual(
'0x2bfc782b6bf66f305fdeb19a203386efee3e62bce3ceb9d3d53eafbe0b14a035',
);
});
it('should retrieve the correct sui address', async () => {
// Get the public key
const publicKey = signer.getPublicKey();
expect(publicKey.toSuiAddress()).toEqual(
'0x2bfc782b6bf66f305fdeb19a203386efee3e62bce3ceb9d3d53eafbe0b14a035',
);
});

it('should sign a message and verify against pubkey', async () => {
// Define a test message
const testMessage = 'Hello, AWS KMS Signer!';
const messageBytes = new TextEncoder().encode(testMessage);
it('should sign a message and verify against pubkey', async () => {
// Define a test message
const testMessage = 'Hello, AWS KMS Signer!';
const messageBytes = new TextEncoder().encode(testMessage);

// Sign the test message
const { signature } = await signer.signPersonalMessage(messageBytes);
// Sign the test message
const { signature } = await signer.signPersonalMessage(messageBytes);

// verify signature against pubkey
const publicKey = signer.getPublicKey();
const isValid = await publicKey.verifyPersonalMessage(messageBytes, signature);
expect(isValid).toBe(true);
});
// verify signature against pubkey
const publicKey = signer.getPublicKey();
const isValid = await publicKey.verifyPersonalMessage(messageBytes, signature);
expect(isValid).toBe(true);
});
}
});

0 comments on commit 5c071ba

Please sign in to comment.