-
Notifications
You must be signed in to change notification settings - Fork 2
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 #1 from n0cte/main
methods and tests
- Loading branch information
Showing
17 changed files
with
16,280 additions
and
1 deletion.
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 @@ | ||
node_modules |
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,65 @@ | ||
name: integration tests | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
release: | ||
types: [ published ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [14.x, 15.x] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- run: npm run test:ganache & | ||
- run: npm run test:start & | ||
- run: sleep 10 && npm test | ||
build: | ||
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | ||
needs: test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Get the version | ||
id: vars | ||
run: echo ::set-output name=sha::$(echo ${GITHUB_SHA:0:7}) | ||
- name: Run docker build | ||
run: docker build -t vulcanize/testing-framework -f Dockerfile . | ||
- name: Tag docker image | ||
run: docker tag vulcanize/testing-framework docker.pkg.github.com/vulcanize/testing-framework/testing-framework:${{steps.vars.outputs.sha}} | ||
- name: Docker Login | ||
if: ${{ github.repository == 'vulcanize/testing-framework' }} | ||
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u vulcanize --password-stdin | ||
- name: Docker Push | ||
if: ${{ github.repository == 'vulcanize/testing-framework' }} | ||
run: docker push docker.pkg.github.com/vulcanize/testing-framework/testing-framework:${{steps.vars.outputs.sha}} | ||
release: | ||
if: ${{ github.repository == 'vulcanize/testing-framework' && github.event_name == 'release' && github.ref == 'refs/heads/published' }} | ||
name: Push Docker image to Docker Hub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get the version | ||
id: vars | ||
run: | | ||
echo ::set-output name=sha::$(echo ${GITHUB_SHA:0:7}) | ||
echo ::set-output name=tag::$(echo ${GITHUB_REF#refs/tags/}) | ||
- name: Docker Login to Github Registry | ||
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u vulcanize --password-stdin | ||
- name: Docker Pull | ||
run: docker pull docker.pkg.github.com/vulcanize/testing-framework/testing-framework:${{steps.vars.outputs.sha}} | ||
- name: Docker Login to Docker Registry | ||
run: echo ${{ secrets.VULCANIZEJENKINS_PAT }} | docker login -u vulcanizejenkins --password-stdin | ||
- name: Tag docker image | ||
run: docker tag docker.pkg.github.com/vulcanize/testing-framework/testing-framework:${{steps.vars.outputs.sha}} vulcanize/testing-framework:${{steps.vars.outputs.tag}} | ||
- name: Docker Push to Docker Hub | ||
run: docker push vulcanize/testing-framework:${{steps.vars.outputs.tag}} |
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,3 @@ | ||
node_modules/ | ||
.DS_Store | ||
.vscode |
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,9 @@ | ||
FROM node:14-alpine3.11 | ||
|
||
WORKDIR /app | ||
COPY . . | ||
RUN npm ci --production | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["npm", "start"] |
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 +1,65 @@ | ||
# testing-framework | ||
# Testing Framework | ||
To start the application, you need to enter the command `npm start` | ||
|
||
__Environment variables__: | ||
- `PORT` - network listening port | ||
- `GETH` - address of geth rpc server | ||
- `ACCOUNTS` - list of private keys separated by commas | ||
|
||
To run the tests you need to enter the commands: | ||
``` | ||
npm run test:ganache | ||
npm run test:start | ||
npm test | ||
``` | ||
|
||
## List of http methods | ||
### Deploy smart-contract | ||
Request: | ||
``` | ||
POST /deploy | ||
Content-Type: application/json | ||
{ | ||
"source": "<smart contract source code>", | ||
"compiler": "<solidity compiler version>", | ||
"contract": { | ||
"name": "<the name of the smart contract, which will be deployed to the blockchain>", | ||
"args": "[<enumeration of smart contract constructor arguments>]", | ||
"from": "<the account address, which will be used when deploying>" | ||
} | ||
} | ||
``` | ||
Response: | ||
``` | ||
{ | ||
uuid: "<unique number of the deployed smart contract>", | ||
address: "<address of the deployed smart contract>" | ||
} | ||
``` | ||
|
||
### Read data from smart-contract | ||
Request: | ||
``` | ||
POST /read | ||
{ | ||
uuid: "<unique number of the deployed smart contract>", | ||
func: "<smart contract method>", | ||
args: "<smart contract method arguments>", | ||
from: "<the account address, which will be used when calling>", | ||
} | ||
``` | ||
Response: depends on smart contract | ||
|
||
### Write data to smart-contract | ||
Request: | ||
``` | ||
POST /send | ||
{ | ||
uuid: "<unique number of the deployed smart contract>", | ||
func: "<smart contract method>", | ||
args: "<smart contract method arguments>", | ||
from: "<the account address, which will be used when calling>", | ||
value: "<amount of wei to be sent to the method>" | ||
} | ||
``` | ||
Response: [transaction receipt](https://web3js.readthedocs.io/en/v1.3.4/web3-eth.html#gettransactionreceipt) |
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,27 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
contract Ownable { | ||
address private owner; | ||
|
||
event OwnerSet(address indexed oldOwner, address indexed newOwner); | ||
|
||
modifier isOwner() { | ||
require(msg.sender == owner, "Caller is not owner"); | ||
_; | ||
} | ||
|
||
constructor() { | ||
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor | ||
emit OwnerSet(address(0), owner); | ||
} | ||
|
||
function changeOwner(address newOwner) public isOwner { | ||
emit OwnerSet(owner, newOwner); | ||
owner = newOwner; | ||
} | ||
|
||
function getOwner() external view returns (address, address) { | ||
return (owner, owner); | ||
} | ||
} |
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,60 @@ | ||
const fs = require('fs'); | ||
const fetch = require('node-fetch'); | ||
|
||
main().catch(console.log); | ||
|
||
async function main() { | ||
const source = fs.readFileSync('./examples/Ownable.sol', { encoding: 'utf-8' }); | ||
const client = tfclient('http://localhost:3000'); | ||
|
||
const resp1 = await client.deploy({ | ||
source: source, | ||
compiler: '0.8.1', | ||
contract: { | ||
from: '0x2e8E6cBe91e4EFAb45Ebb21b9Aef64283F26833b', | ||
name: 'Ownable', | ||
args: [], | ||
} | ||
}) | ||
console.log(resp1); | ||
|
||
const resp2 = await client.read({ | ||
uuid: resp1.uuid, | ||
func: 'getOwner', | ||
args: [], | ||
from: '0x2e8E6cBe91e4EFAb45Ebb21b9Aef64283F26833b' | ||
}); | ||
console.log(resp2); | ||
|
||
const resp3 = await client.send({ | ||
uuid: resp1.uuid, | ||
func: 'changeOwner', | ||
args: ['0x2e8E6cBe91e4EFAb45Ebb21b9Aef64283F26833b'], | ||
from: '0x2e8E6cBe91e4EFAb45Ebb21b9Aef64283F26833b' | ||
}); | ||
console.log(resp3); | ||
} | ||
|
||
function tfclient(basepath) { | ||
async function post(method, data) { | ||
const res = await fetch(`${basepath}/${method}`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(data) | ||
}); | ||
return res.json(); | ||
} | ||
return { | ||
deploy(data) { | ||
return post('deploy', data) | ||
}, | ||
read(data) { | ||
return post('read', data) | ||
}, | ||
send(data) { | ||
return post('send', data) | ||
} | ||
} | ||
} |
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,20 @@ | ||
|
||
const fastify = require('fastify')({ logger: true }); | ||
const web3 = require('./src/web3'); | ||
|
||
const port = process.env.PORT || '3000'; | ||
const geth = process.env.GETH || 'http://localhost:8545'; | ||
const accs = process.env.ACCOUNTS || ''; | ||
|
||
web3.init(geth, accs); | ||
fastify.register(require('./src/deploy')); | ||
fastify.register(require('./src/read')); | ||
fastify.register(require('./src/send')); | ||
|
||
fastify.listen(port, function (err, address) { | ||
if (err) { | ||
fastify.log.error(err) | ||
process.exit(1) | ||
} | ||
fastify.log.info(`server listening on ${address}`) | ||
}); |
Oops, something went wrong.