integration test #53

Merged
ramilexe merged 32 commits from integration_tests into endpoints 2021-06-18 06:59:19 +00:00
9 changed files with 27342 additions and 0 deletions
Showing only changes of commit 141b3eaffe - Show all commits

5
test/contract/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
node_modules
#Hardhat files
cache
artifacts

View File

@ -0,0 +1,21 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.7.0;
contract Greeter {
string greeting;
event Greet(string value);
constructor(string memory _greeting) {
greeting = _greeting;
}
function greet() public view returns (string memory) {
return greeting;
}
function setGreeting(string memory _greeting) public {
greeting = _greeting;
emit Greet(greeting);
}
}

View File

@ -0,0 +1,28 @@
require("@nomiclabs/hardhat-waffle");
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async () => {
const accounts = await ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.7.3",
networks: {
local: {
url: 'http://127.0.0.1:8545',
chainId: 4
}
}
};

27136
test/contract/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
{
"name": "contract",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"hardhat": "^2.2.0"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"chai": "^4.3.4",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.1.0"
}
}

View File

@ -0,0 +1,32 @@
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
//
// If this script is run directly using `node` you may want to call compile
// manually to make sure everything is compiled
// await hre.run('compile');
// We get the contract to deploy
const Greeter = await hre.ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, Hardhat!");
await greeter.deployed();
console.log("Greeter deployed to:", greeter.address, "; tx hash: ", greeter.deployTransaction.hash);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});

View File

@ -0,0 +1,14 @@
const { expect } = require("chai");
describe("Greeter", function() {
it("Should return the new greeting once it's changed", async function() {
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, world!");
await greeter.deployed();
expect(await greeter.greet()).to.equal("Hello, world!");
await greeter.setGreeting("Hola, mundo!");
expect(await greeter.greet()).to.equal("Hola, mundo!");
});
});

View File

@ -0,0 +1,19 @@
package integration_test
import (
"github.com/sirupsen/logrus"
"io/ioutil"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestIntegration(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "integration test suite")
}
var _ = BeforeSuite(func() {
logrus.SetOutput(ioutil.Discard)
})

65
test/integration_test.go Normal file
View File

@ -0,0 +1,65 @@
package integration_test
import (
"context"
"math/big"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ethereum/go-ethereum/ethclient"
)
var _ = Describe("Integration test", func() {
gethHttpPath := "http://127.0.0.1:8545"
gethClient, err := ethclient.Dial(gethHttpPath)
Expect(err).ToNot(HaveOccurred())
ipldEthHttpPath := "http://127.0.0.1:8081"
ipldClient, err := ethclient.Dial(ipldEthHttpPath)
Expect(err).ToNot(HaveOccurred())
Describe("get Block", func() {
ctx := context.Background()
gethBlock, err := gethClient.BlockByNumber(ctx, big.NewInt(1))
Expect(err).ToNot(HaveOccurred())
Expect(gethBlock).ToNot(BeEmpty())
ipldBlock, err := ipldClient.BlockByNumber(ctx, big.NewInt(1))
Expect(err).ToNot(HaveOccurred())
Expect(ipldBlock).ToNot(BeEmpty())
})
})
//func Test1(t *testing.T) {
// gethHttpPath := "http://127.0.0.1:8545"
// gethClient, err := ethclient.Dial(gethHttpPath)
// if err != nil {
// t.Fatal(err)
// }
//
// ipldEthHttpPath := "http://127.0.0.1:8081"
// ipldClient, err := ethclient.Dial(ipldEthHttpPath)
// if err != nil {
// t.Fatal(err)
// }
//
// ctx := context.Background()
//
// gethBlock, err := gethClient.BlockByNumber(ctx, big.NewInt(1))
// if err != nil {
// t.Fatal(err)
// }
// ipldBlock, err := ipldClient.BlockByNumber(ctx, big.NewInt(1))
// if err != nil {
// t.Fatal(err)
// }
//
// t.Logf("Geth Block header: %+v", gethBlock.Header())
// t.Logf("IPLD Block header: %+v", ipldBlock.Header())
//
// t.Log("asdasd")
//}