Skip to content

Commit

Permalink
chore: update and cleanup contract test, env, expose ACI
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Apr 29, 2024
1 parent 5c5b924 commit a51ff1d
Show file tree
Hide file tree
Showing 39 changed files with 4,595 additions and 1,016 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@master
- name: Use Node.js 14.x
uses: actions/setup-node@v1
uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 14.x
node-version: 20.x
- run: npm install -g @aeternity/aeproject
- run: npm install
- run: aeproject env
- run: npm test
- run: aeproject test
- run: |
npm run generate-bytecode-aci-hashes
git diff --exit-code
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
node_modules
.aeproject-store
.DS_Store
package-lock.json
*.iml
.idea

*.aes.js
generated/*.aes.js
94 changes: 94 additions & 0 deletions .scripts/generate-bytecode-aci-hashes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const { utils, networks } = require("@aeternity/aeproject");
const fs = require("fs");
const crypto = require("crypto");
const path = require("path");
const { CompilerHttp, hash, getFileSystem} = require("@aeternity/aepp-sdk");

// add contract paths from base
const CONTRACTS = [
"v1/Tipping_v1.aes",
"v1/Tipping_v1_Getter.aes",
"v2/Tipping_v2.aes",
"v3/Tipping_v3.aes",
"v3/Tipping_v3_Getter.aes",
"v4/Tipping_v4.aes",
];

function generateSourceHashes() {
const hashes = CONTRACTS.reduce((acc, contract) => {
const source = fs.readFileSync("./contracts/" + contract, "utf-8");
acc[contract] = Buffer.from(hash(source)).toString("base64");
return acc;
}, {});

fs.writeFileSync(
"./generated/source_hashes.json",
JSON.stringify(hashes, null, 2),
);
}

function writeAci(aci, contract) {
fs.writeFileSync(
`${__dirname}/../generated/${path.basename(contract, ".aes")}.aci.json`,
JSON.stringify(aci, null, 2),
"utf-8",
);
}

async function generateBytecodeAci() {
const aeSdk = await utils.getSdk();

const bytecode_hashes = await CONTRACTS.reduce(
async (promiseAcc, contract) => {
const acc = await promiseAcc;
const fileSystem = await getFileSystem(
"./contracts/" + contract,
);
let sourceCode = utils.getContractContent("./contracts/" + contract);

try {
const compiled = await aeSdk.compilerApi.compileBySourceCode(
sourceCode,
fileSystem,
);

const compilerVersion = await aeSdk.compilerApi.version();
if (!acc[compilerVersion]) acc[compilerVersion] = {};

acc[compilerVersion][contract] = {
hash: crypto
.createHash("sha256")
.update(compiled.bytecode)
.digest("hex"),
bytecode: compiled.bytecode,
};

writeAci(compiled.aci, contract);
} catch (e) {
console.log(
"falling back to just aci generation without compilation for",
contract,
e.message,
);

const compilerHttp = new CompilerHttp(networks.devmode.compilerUrl);
await compilerHttp
.generateAciBySourceCode(sourceCode, fileSystem)
.then((aci) => writeAci(aci, contract))
.catch(console.error);
}

return acc;
},
Promise.resolve({}),
);

fs.writeFileSync(
"./generated/bytecode_hashes.json",
JSON.stringify(bytecode_hashes, null, 2),
"utf-8",
);
}

generateSourceHashes();
void generateBytecodeAci();
19 changes: 0 additions & 19 deletions .scripts/postinstall.js

This file was deleted.

17 changes: 0 additions & 17 deletions config/network.json

This file was deleted.

44 changes: 0 additions & 44 deletions config/wallets.json

This file was deleted.

Loading

0 comments on commit a51ff1d

Please sign in to comment.