-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Arbitrary Contract Interactions
- Loading branch information
1 parent
79aa578
commit 3afce82
Showing
8 changed files
with
502 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,5 @@ yarn-error.log* | |
.vscode | ||
|
||
.idea | ||
.cosine | ||
.cosine | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { catchAsync } = require("../../services/response.util"); | ||
const { getContractEndpoints } = require("../../services/aci.service"); | ||
|
||
const getContractEndpointsController = catchAsync(async(req, response) => { | ||
const {network} = req.body; | ||
const contractId = req.params.contract_id; | ||
if(!contractId) throw new Error("Contract ID is required"); | ||
|
||
let [endpoints, error] = await getContractEndpoints(network, contractId) | ||
if(error) throw new Error(error) | ||
|
||
if(endpoints){ | ||
endpoints = { | ||
...endpoints, | ||
operations: endpoints.children.map(x => x.name) | ||
} | ||
} | ||
|
||
return response.json(endpoints); | ||
}) | ||
|
||
module.exports = { | ||
getContractEndpointsController | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const express = require("express"); | ||
const { getContractEndpointsController } = require("../components/aci"); | ||
|
||
/** | ||
* TEST Contracts | ||
* | ||
* KT1MzN5jLkbbq9P6WEFmTffUrYtK8niZavzH | ||
* KT1VG3ynsnyxFGzw9mdBwYnyZAF8HZvqnNkw | ||
* | ||
*/ | ||
|
||
const aciRoutes = express.Router(); | ||
|
||
/** | ||
* @swagger | ||
* /aci/{contract_id}: | ||
* post: | ||
* summary: Get contract endpoints | ||
* tags: [ACI] | ||
* parameters: | ||
* - in: path | ||
* name: contract_id | ||
* required: true | ||
* description: The ID of the contract | ||
* schema: | ||
* type: string | ||
* requestBody: | ||
* required: false | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* network: | ||
* type: string | ||
* responses: | ||
* 200: | ||
* description: Contract ACI Endpoints | ||
*/ | ||
aciRoutes.post('/aci/:contract_id', getContractEndpointsController) | ||
|
||
module.exports = aciRoutes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const request = require("supertest"); | ||
const express = require("express"); | ||
const aciRoutes = require("./aci"); | ||
|
||
const app = express(); | ||
app.use(express.json()); | ||
app.use("/", aciRoutes); | ||
|
||
const contractIds = [ | ||
"KT1MzN5jLkbbq9P6WEFmTffUrYtK8niZavzH", | ||
"KT1VG3ynsnyxFGzw9mdBwYnyZAF8HZvqnNkw", | ||
"I_AM_INVALID_ID" | ||
] | ||
|
||
describe("ACI Routes", () => { | ||
it("should return bad status on invalid address ", async () => { | ||
await request(app) | ||
.post(`/aci/${contractIds[2]}`) | ||
.expect(400) | ||
.expect("Content-Type", /json/) | ||
}); | ||
it("should return valid status on valid address ", async () => { | ||
await request(app) | ||
.post(`/aci/${contractIds[0]}`) | ||
.send({network:"ghostnet"}) | ||
.expect(200) | ||
.expect("Content-Type", /json/) | ||
}); | ||
it("should return valid JSON on valid address", async () => { | ||
const res = await request(app) | ||
.post(`/aci/${contractIds[0]}`) | ||
.send({network:"ghostnet"}) | ||
.expect(200) | ||
.expect("Content-Type", /json/) | ||
|
||
expect(res.body).toHaveProperty("counter"); | ||
expect(res.body).toHaveProperty("name"); | ||
expect(res.body).toHaveProperty("type"); | ||
expect(res.body).toHaveProperty("children"); | ||
expect(res.body).toHaveProperty("operations"); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.