Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions packages/api-http/integration/routes/legacy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { describe } from "@mainsail/test-runner";
import { Application } from "@mainsail/kernel";
import { prepareSandbox, ApiContext } from "../../test/helpers/prepare-sandbox";
import { request } from "../../test/helpers/request";

import legacyColdWallets from "../../test/fixtures/legacy_cold_wallets.json";

describe<{
app: Application;
}>("Legacy", ({ it, afterAll, assert, afterEach, beforeAll, beforeEach, nock }) => {
let apiContext: ApiContext;

let options = {};

beforeAll(async (context) => {
nock.enableNetConnect();
apiContext = await prepareSandbox(context);
});

afterAll((context) => {
nock.disableNetConnect();
apiContext.dispose();
});

beforeEach(async (context) => {
await apiContext.reset();
});

afterEach(async (context) => {
await apiContext.reset();
});

it("/legacy/cold-wallets", async () => {
await apiContext.legacyColdWalletRepository.save(legacyColdWallets);

const { statusCode, data } = await request("/legacy/cold-wallets", options);
assert.equal(statusCode, 200);
assert.equal(data.data, legacyColdWallets);
});

it("/legacy/cold-wallets/{address}", async () => {
await apiContext.legacyColdWalletRepository.save(legacyColdWallets);

const wallet = legacyColdWallets[0];

const {
statusCode,
data: { data },
} = await request(`/legacy/cold-wallets/${wallet.address}`, options);

assert.equal(statusCode, 200);
assert.equal(data, wallet);
});

it("/legacy/cold-wallets/{address} (404)", async () => {
await apiContext.legacyColdWalletRepository.save(legacyColdWallets);

const fake = "1".repeat(34);

await assert.rejects(
async () => request(`/legacy/cold-wallets/${fake}`, options),
"Response code 404 (Not Found)",
);
});
});
17 changes: 17 additions & 0 deletions packages/api-http/source/controllers/legacy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Boom from "@hapi/boom";
import Hapi from "@hapi/hapi";
import { Contracts as ApiDatabaseContracts, Identifiers as ApiDatabaseIdentifiers } from "@mainsail/api-database";
import { inject, injectable } from "@mainsail/container";
Expand Down Expand Up @@ -30,4 +31,20 @@ export class LegacyController extends Controller {
LegacyColdWalletResource,
);
}

public async showColdWallet(request: Hapi.Request): Promise<object> {
const legacyAddress = request.params.address;

const wallet = await this.legacyColdWalletRepositoryFactory()
.createQueryBuilder()
.select()
.where("address = :legacyAddress", { legacyAddress })
.getOne();

if (!wallet) {
return Boom.notFound("Cold Wallet not found");
}

return this.respondWithResource(wallet, LegacyColdWalletResource);
}
}
15 changes: 15 additions & 0 deletions packages/api-http/source/routes/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Contracts } from "@mainsail/contracts";
import Joi from "joi";

import { LegacyController } from "../controllers/legacy.js";
import { legacyAddressSchema } from "../schemas/legacy.js";

export const register = (server: Contracts.Api.ApiServer): void => {
const controller = server.app.app.resolve(LegacyController);
Expand All @@ -24,4 +25,18 @@ export const register = (server: Contracts.Api.ApiServer): void => {
},
path: "/legacy/cold-wallets",
});

server.route({
handler: (request: Hapi.Request) => controller.showColdWallet(request),
method: "GET",
options: {
validate: {
params: Joi.object({
address: legacyAddressSchema,
}),
query: Joi.object({}),
},
},
path: "/legacy/cold-wallets/{address}",
});
};
1 change: 1 addition & 0 deletions packages/api-http/source/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./blocks.js";
export * from "./legacy.js";
export * from "./schemas.js";
export * from "./tokens.js";
export * from "./transactions.js";
Expand Down
6 changes: 6 additions & 0 deletions packages/api-http/source/schemas/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Joi from "joi";

export const legacyAddressSchema = Joi.string()
.min(33)
.max(34)
.pattern(/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/);
20 changes: 20 additions & 0 deletions packages/api-http/test/fixtures/legacy_cold_wallets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"address": "D598Pv4evuAPsvcXTaBq6Ru1by5sTXpX8H",
"balance": "10000000000",
"attributes": {
"legacyNonce": "0"
},
"mergeInfoWalletAddress": null,
"mergeInfoTransactionHash": null
},
{
"address": "D599XZcmRs5D6FALivh43uThAFKCT9vST8",
"balance": "10000000000",
"attributes": {
"legacyNonce": "0"
},
"mergeInfoWalletAddress": null,
"mergeInfoTransactionHash": null
}
]
6 changes: 6 additions & 0 deletions packages/api-http/test/helpers/prepare-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ export class ApiContext {
)();
}

public get legacyColdWalletRepository(): ApiDatabaseContracts.LegacyColdWalletRepository {
return this.app.get<ApiDatabaseContracts.LegacyColdWalletRepositoryFactory>(
ApiDatabaseIdentifiers.LegacyColdWalletRepositoryFactory,
)();
}

public get validatorRoundRepository(): ApiDatabaseContracts.ValidatorRoundRepository {
return this.app.get<ApiDatabaseContracts.ValidatorRoundRepositoryFactory>(
ApiDatabaseIdentifiers.ValidatorRoundRepositoryFactory,
Expand Down
Loading