Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
oXtxNt9U committed Nov 28, 2024
1 parent a441619 commit 681e85f
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 6 deletions.
54 changes: 54 additions & 0 deletions packages/api-http/integration/routes/contracts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { describe, Sandbox } from "../../../test-framework/source";
import contracts from "../../test/fixtures/contracts.json";
import contractsResponse from "../../test/fixtures/contracts-response.json";
import { ApiContext, prepareSandbox } from "../../test/helpers/prepare-sandbox";
import { request } from "../../test/helpers/request";

describe<{
sandbox: Sandbox;
}>("ApiNodes", ({ it, afterAll, assert, afterEach, beforeAll, beforeEach, nock }) => {
let apiContext: ApiContext;

const 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("/contracts", async () => {
let { statusCode, data } = await request("/contracts", options);
assert.equal(statusCode, 200);
assert.empty(data.data);

await apiContext.contractRepository.save(contracts);

({ statusCode, data } = await request("/contracts", options));
assert.equal(data.data, contractsResponse);
});

it("/contracts/{name}/{implementation}/abi", async () => {
await apiContext.contractRepository.save(contracts);

let contract = contracts[contracts.length - 1];
let { data } = await request(`/contracts/${contract.name}/${contract.activeImplementation}/abi`, options);
assert.equal(data.data, { abi: contract.implementations[0].abi });

contract = contracts[0];
({ data } = await request(`/contracts/${contract.name}/${contract.implementations[1].address}/abi`, options));
assert.equal(data.data, { abi: contract.implementations[1].abi });
});
});
27 changes: 27 additions & 0 deletions packages/api-http/test/fixtures/contracts-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"consensus": {
"address": "0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1",
"proxy": "UUPS",
"implementations": [
"0x522B3294E6d06aA25Ad0f1B8891242E335D3B459",
"0x622B3294E6d06aA25Ad0f1B8891242E335D3B459"
],
"activeImplementation": "0x522B3294E6d06aA25Ad0f1B8891242E335D3B459"
},
"multi-payments": {
"address": "0x83769BeEB7e5405ef0B7dc3C66C43E3a51A6d27f",
"proxy": null,
"implementations": [
"0x83769BeEB7e5405ef0B7dc3C66C43E3a51A6d27f"
],
"activeImplementation": null
},
"usernames": {
"address": "0x2c1DE3b4Dbb4aDebEbB5dcECAe825bE2a9fc6eb6",
"proxy": "UUPS",
"implementations": [
"0xc051134F56d56160E8c8ed9bB3c439c78AB27cCc"
],
"activeImplementation": "0xc051134F56d56160E8c8ed9bB3c439c78AB27cCc"
}
}
50 changes: 50 additions & 0 deletions packages/api-http/test/fixtures/contracts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"name": "consensus",
"address": "0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1",
"proxy": "UUPS",
"implementations": [
{
"address": "0x522B3294E6d06aA25Ad0f1B8891242E335D3B459",
"abi": {
"consensus": 1
}
},
{
"address": "0x622B3294E6d06aA25Ad0f1B8891242E335D3B459",
"abi": {
"consensus": 2
}
}
],
"activeImplementation": "0x522B3294E6d06aA25Ad0f1B8891242E335D3B459"
},
{
"name": "multi-payments",
"address": "0x83769BeEB7e5405ef0B7dc3C66C43E3a51A6d27f",
"proxy": null,
"implementations": [
{
"address": "0x83769BeEB7e5405ef0B7dc3C66C43E3a51A6d27f",
"abi": {
"multi-payments": 1
}
}
],
"activeImplementation": null
},
{
"name": "usernames",
"address": "0x2c1DE3b4Dbb4aDebEbB5dcECAe825bE2a9fc6eb6",
"proxy": "UUPS",
"implementations": [
{
"address": "0xc051134F56d56160E8c8ed9bB3c439c78AB27cCc",
"abi": {
"usernames": 1
}
}
],
"activeImplementation": "0xc051134F56d56160E8c8ed9bB3c439c78AB27cCc"
}
]
12 changes: 6 additions & 6 deletions packages/api-http/test/helpers/prepare-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export class ApiContext {
)();
}

public get contractRepository(): ApiDatabaseContracts.ContractRepository {
return this.app.get<ApiDatabaseContracts.ContractRepositoryFactory>(
ApiDatabaseIdentifiers.ContractRepositoryFactory,
)();
}

public get transactionRepository(): ApiDatabaseContracts.TransactionRepository {
return this.app.get<ApiDatabaseContracts.TransactionRepositoryFactory>(
ApiDatabaseIdentifiers.TransactionRepositoryFactory,
Expand All @@ -44,12 +50,6 @@ export class ApiContext {
)();
}

public get mempoolTransactionRepository(): ApiDatabaseContracts.MempoolTransactionRepository {
return this.app.get<ApiDatabaseContracts.MempoolTransactionRepositoryFactory>(
ApiDatabaseIdentifiers.MempoolTransactionRepositoryFactory,
)();
}

public get walletRepository(): ApiDatabaseContracts.WalletRepository {
return this.app.get<ApiDatabaseContracts.WalletRepositoryFactory>(
ApiDatabaseIdentifiers.WalletRepositoryFactory,
Expand Down

0 comments on commit 681e85f

Please sign in to comment.