Skip to content

Commit

Permalink
test: check kms account can sign transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaaa committed Apr 24, 2024
1 parent 38c6115 commit d7c6674
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions e2e/packages/sync-test/kms.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { describe, expect, it } from "vitest";
import { createAsyncErrorHandler } from "./asyncErrors";
import { rpcHttpUrl } from "./setup/constants";
import { createKmsAccount } from "@latticexyz/common";
import { CreateKeyCommand, KMSClient } from "@aws-sdk/client-kms";
import { createPublicClient, http } from "viem";
import { mudFoundry } from "@latticexyz/common/chains";

describe("KMS", async () => {
const asyncErrorHandler = createAsyncErrorHandler();

it("should sync test data", async () => {
asyncErrorHandler.resetErrors();

const kmsClient = new KMSClient({
endpoint: process.env.KMS_ENDPOINT,
region: "local",
credentials: {
accessKeyId: "AKIAXTTRUF7NU7KDMIED",
secretAccessKey: "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",
},
});

// Create a new KMS key
const command = new CreateKeyCommand({
KeyUsage: "SIGN_VERIFY",
CustomerMasterKeySpec: "ECC_SECG_P256K1",
});

const createResponse = await kmsClient.send(command);

if (!createResponse.KeyMetadata || !createResponse.KeyMetadata.KeyId) {
throw new Error("key creation failed");
}

const keyId = createResponse.KeyMetadata.KeyId;

// Declare a KMS Account
const account = await createKmsAccount({
keyId,
client: kmsClient,
});

const publicClient = createPublicClient({
chain: mudFoundry,
transport: http(rpcHttpUrl),
});

// Check the balance of the KMS account
const balance = await publicClient.getBalance({ address: account.address });

expect(balance).toEqual(0);
});
});

0 comments on commit d7c6674

Please sign in to comment.