-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from MystenLabs/SE-634-integrate-linter
SE-634 integrate linter
- Loading branch information
Showing
15 changed files
with
499 additions
and
371 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Check Code Formatting | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
prettier-check: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: 1.0.11 | ||
|
||
- name: Install dependencies | ||
run: bun install | ||
|
||
- name: Run Prettier check | ||
run: bun run check-format |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,27 +1,29 @@ | ||
const topic = "job-events" | ||
const topic = "job-events"; | ||
const server = Bun.serve({ | ||
port: 3001, | ||
fetch(request, server){ | ||
if (server.upgrade(request)){ | ||
return; | ||
} | ||
return new Response("Established websocket connection with the notifier service."); | ||
}, | ||
websocket:{ | ||
open(ws){ | ||
ws.subscribe(topic); | ||
console.log("Notifier is up and running! Websocket connection is open."); | ||
}, | ||
message(ws, message){ | ||
console.log(`Incoming message: ${message}`); | ||
// TODO: only broadcast when receiving message from request processor | ||
// ie. authenticate the request processor using a token | ||
server.publish(topic, message); | ||
}, | ||
close(_){ | ||
console.log("Connection to notifier service has been closed!"); | ||
} | ||
port: 3001, | ||
fetch(request, server) { | ||
if (server.upgrade(request)) { | ||
return; | ||
} | ||
return new Response( | ||
"Established websocket connection with the notifier service.", | ||
); | ||
}, | ||
websocket: { | ||
open(ws) { | ||
ws.subscribe(topic); | ||
console.log("Notifier is up and running! Websocket connection is open."); | ||
}, | ||
message(ws, message) { | ||
console.log(`Incoming message: ${message}`); | ||
// TODO: only broadcast when receiving message from request processor | ||
// ie. authenticate the request processor using a token | ||
server.publish(topic, message); | ||
}, | ||
close(_) { | ||
console.log("Connection to notifier service has been closed!"); | ||
}, | ||
}, | ||
}); | ||
|
||
console.log(`Websocket server listening on ${server.port}`); |
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,10 @@ | ||
{ | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"prettier": "3.3.2" | ||
}, | ||
"scripts": { | ||
"fix-format": "bun prettier . --write", | ||
"check-format": "bun prettier . --check" | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,49 +1,57 @@ | ||
import { expect, test } from "bun:test"; | ||
import { app } from "../app"; | ||
import request from "supertest"; | ||
import request from "supertest"; | ||
|
||
test("Healthcheck endpoint returns status 200", async () => { | ||
await request(app) | ||
.get("/healthcheck") | ||
.then(response => { | ||
.then((response) => { | ||
expect(response.statusCode).toBe(200); | ||
}) | ||
}) | ||
}); | ||
}); | ||
|
||
test("Accept request for processing", async () => { | ||
await request(app) | ||
.post("/") | ||
.send({ | ||
"smart_contract_function_name": "mint_nft", | ||
"smart_contract_function_arguments": ["0x9320eaaf945570b1baf7607f98a9cf5585fdcb8ed09d46da93199fee16b48196"], | ||
"receiver_address": "0xe40c8cf8b53822829b3a6dc9aea84b62653f60b771e9da4bd4e214cae851b87b" | ||
smart_contract_function_name: "mint_nft", | ||
smart_contract_function_arguments: [ | ||
"0x9320eaaf945570b1baf7607f98a9cf5585fdcb8ed09d46da93199fee16b48196", | ||
], | ||
receiver_address: | ||
"0xe40c8cf8b53822829b3a6dc9aea84b62653f60b771e9da4bd4e214cae851b87b", | ||
}) | ||
.then(response => { | ||
.then((response) => { | ||
expect(response.statusCode).toBe(202); | ||
}) | ||
}) | ||
}); | ||
}); | ||
|
||
test("Accept request without receiver_address", async () => { | ||
await request(app) | ||
.post("/") | ||
.send({ | ||
"smart_contract_function_name": "mint_nft", | ||
"smart_contract_function_arguments": ["0x9320eaaf945570b1baf7607f98a9cf5585fdcb8ed09d46da93199fee16b48196"], | ||
smart_contract_function_name: "mint_nft", | ||
smart_contract_function_arguments: [ | ||
"0x9320eaaf945570b1baf7607f98a9cf5585fdcb8ed09d46da93199fee16b48196", | ||
], | ||
}) | ||
.then(response => { | ||
.then((response) => { | ||
expect(response.statusCode).toBe(202); | ||
}) | ||
}) | ||
}); | ||
}); | ||
|
||
test("Reject when smart_contract_function_name is empty", async () => { | ||
await request(app) | ||
.post("/") | ||
.send({ | ||
"smart_contract_function_name": "", | ||
"smart_contract_function_arguments": ["0x9320eaaf945570b1baf7607f98a9cf5585fdcb8ed09d46da93199fee16b48196"], | ||
"receiver_address": "0xe40c8cf8b53822829b3a6dc9aea84b62653f60b771e9da4bd4e214cae851b87b" | ||
smart_contract_function_name: "", | ||
smart_contract_function_arguments: [ | ||
"0x9320eaaf945570b1baf7607f98a9cf5585fdcb8ed09d46da93199fee16b48196", | ||
], | ||
receiver_address: | ||
"0xe40c8cf8b53822829b3a6dc9aea84b62653f60b771e9da4bd4e214cae851b87b", | ||
}) | ||
.then(response => { | ||
.then((response) => { | ||
expect(response.statusCode).toBe(400); | ||
}) | ||
}) | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,46 +1,50 @@ | ||
import { fromB64 } from "@mysten/sui/utils"; | ||
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"; | ||
import { SuiClient, getFullnodeUrl } from "@mysten/sui/client"; | ||
import { aggregateMoveCallsIntoATransaction} from "./prepareTransaction"; | ||
import { aggregateMoveCallsIntoATransaction } from "./prepareTransaction"; | ||
import { ParallelTransactionExecutor } from "@mysten/sui/transactions"; | ||
import { QueueObject } from "../../request_handler/queue"; | ||
import { envVariables } from "../utils/config"; | ||
|
||
type SuiNetwork = 'mainnet' | 'testnet' | 'devnet'; | ||
type SuiNetwork = "mainnet" | "testnet" | "devnet"; | ||
const parseNetwork = (network: string | undefined): SuiNetwork => { | ||
if (network === 'mainnet' || network === 'testnet' || network === 'devnet') { | ||
if (network === "mainnet" || network === "testnet" || network === "devnet") { | ||
return network; | ||
} else { | ||
console.warn(`Invalid network: ${network}, defaulting to testnet`); | ||
return 'testnet'; | ||
return "testnet"; | ||
} | ||
} | ||
const suiClient = new SuiClient({url: getFullnodeUrl( | ||
parseNetwork(process.env.SUI_NETWORK) | ||
)}); | ||
}; | ||
const suiClient = new SuiClient({ | ||
url: getFullnodeUrl(parseNetwork(process.env.SUI_NETWORK)), | ||
}); | ||
|
||
let adminPrivateKeyArray = Uint8Array.from( | ||
Array.from(fromB64(envVariables.ADMIN_SECRET_KEY!)) | ||
Array.from(fromB64(envVariables.ADMIN_SECRET_KEY!)), | ||
); | ||
|
||
const adminKeypair = Ed25519Keypair.fromSecretKey( | ||
adminPrivateKeyArray.slice(1) | ||
adminPrivateKeyArray.slice(1), | ||
); | ||
|
||
const executor = new ParallelTransactionExecutor({ | ||
client: suiClient, | ||
signer: adminKeypair, | ||
coinBatchSize: parseInt(process.env.PTE_COIN_BATCH_SIZE ?? '20'), | ||
initialCoinBalance: BigInt(process.env.PTE_INITIAL_COIN_BALANCE ?? 5_000_000_000), | ||
minimumCoinBalance: BigInt(process.env.PTE_MINIMUM_COIN_BALANCE ?? 500_000_000), | ||
coinBatchSize: parseInt(process.env.PTE_COIN_BATCH_SIZE ?? "20"), | ||
initialCoinBalance: BigInt( | ||
process.env.PTE_INITIAL_COIN_BALANCE ?? 5_000_000_000, | ||
), | ||
minimumCoinBalance: BigInt( | ||
process.env.PTE_MINIMUM_COIN_BALANCE ?? 500_000_000, | ||
), | ||
// The maximum number of gas coins to keep in the gas pool, | ||
// which also limits the maximum number of concurrent transactions | ||
maxPoolSize: parseInt(process.env.PTE_MAX_POOL_SIZE ?? '10'), | ||
}) | ||
maxPoolSize: parseInt(process.env.PTE_MAX_POOL_SIZE ?? "10"), | ||
}); | ||
|
||
export async function executeTransaction(receivers: QueueObject[]) { | ||
const transaction = await aggregateMoveCallsIntoATransaction(receivers) | ||
const res = await executor.executeTransaction(transaction) | ||
const transaction = await aggregateMoveCallsIntoATransaction(receivers); | ||
const res = await executor.executeTransaction(transaction); | ||
|
||
return {status: res.effects, digest: res.digest}; | ||
return { status: res.effects, digest: res.digest }; | ||
} |
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
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