Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
simplify some scenario tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eggplantzzz committed Jun 30, 2022
1 parent f463b25 commit bf8375a
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 75 deletions.
53 changes: 9 additions & 44 deletions packages/truffle/test/scenarios/happy_path/happypath.js
@@ -1,21 +1,20 @@
const { default: Box } = require("@truffle/box");
const sandbox = require("../sandbox");
const MemoryLogger = require("../MemoryLogger");
const CommandRunner = require("../commandRunner");
const contract = require("@truffle/contract");
const fs = require("fs");
const path = require("path");
const assert = require("assert");
const { assert } = require("chai");
const Server = require("../server");

describe("Happy path (truffle unbox)", function () {
describe("basic commands on a fresh project", function () {
let config;
let options;
const logger = new MemoryLogger();
const project = path.join(__dirname, "../../sources/toyProject");

before(async () => {
await Server.start();
options = { name: "default", force: true };
config = await Box.sandbox(options);
config = await sandbox.create(project);
config.network = "development";
config.logger = logger;
});
Expand All @@ -25,19 +24,7 @@ describe("Happy path (truffle unbox)", function () {

it("compiles", async function () {
this.timeout(20000);

await CommandRunner.run("compile", config);

assert(
fs.existsSync(
path.join(config.contracts_build_directory, "MetaCoin.json")
)
);
assert(
fs.existsSync(
path.join(config.contracts_build_directory, "ConvertLib.json")
)
);
assert(
fs.existsSync(
path.join(config.contracts_build_directory, "Migrations.json")
Expand All @@ -47,42 +34,20 @@ describe("Happy path (truffle unbox)", function () {

it("migrates", async function () {
this.timeout(50000);

await CommandRunner.run("migrate", config);

const MetaCoin = contract(
require(path.join(config.contracts_build_directory, "MetaCoin.json"))
);
const ConvertLib = contract(
require(path.join(config.contracts_build_directory, "ConvertLib.json"))
);
const Migrations = contract(
require(path.join(config.contracts_build_directory, "Migrations.json"))
);
Migrations.setProvider(config.provider);

const promises = [];

[MetaCoin, ConvertLib, Migrations].forEach(function (abstraction) {
abstraction.setProvider(config.provider);

promises.push(
abstraction.deployed().then(function (instance) {
assert.notEqual(
instance.address,
null,
instance.contract_name + " didn't have an address!"
);
})
);
});
await Promise.all(promises);
const instance = await Migrations.deployed();
assert.isNotNull(instance.address);
});

it("runs tests", async function () {
this.timeout(70000);
await CommandRunner.run("test", config);
const output = logger.contents();

assert(output.indexOf("5 passing") >= 0);
assert(output.indexOf("0 passing") >= 0);
});
});
13 changes: 4 additions & 9 deletions packages/truffle/test/scenarios/migrations/describe-json.js
Expand Up @@ -126,16 +126,11 @@ describe("truffle migrate --describe-json", () => {
describe("without existing migration (i.e. clean slate)", () => {
let statuses = [];

before("before all setup", done => {
before(async () => {
projectPath = path.join(__dirname, "../../sources/migrations/init");
sandbox
.create(projectPath)
.then(conf => {
config = conf;
config.network = "development";
config.logger = logger;
})
.then(done);
config = await sandbox.create(projectPath);
config.network = "development";
config.logger = logger;
});

it("runs the migration without throwing", async () => {
Expand Down
5 changes: 1 addition & 4 deletions packages/truffle/test/scenarios/migrations/init.js
Expand Up @@ -19,10 +19,7 @@ describe("solo migration", function () {
config = await sandbox.create(project);
config.network = "development";
config.logger = logger;
const provider = new Web3.providers.HttpProvider("http://localhost:8545", {
keepAlive: false
});
web3 = new Web3(provider);
web3 = new Web3("http://localhost:8545");
networkId = await web3.eth.net.getId();
});
after(async function () {
Expand Down
6 changes: 1 addition & 5 deletions packages/truffle/test/scenarios/migrations/migrate.js
Expand Up @@ -19,11 +19,7 @@ describe("migrate (success)", function () {
config = await sandbox.create(project);
config.network = "development";
config.logger = logger;

const provider = new Web3.providers.HttpProvider("http://localhost:8545", {
keepAlive: false
});
web3 = new Web3(provider);
web3 = new Web3("http://localhost:8545");
networkId = await web3.eth.net.getId();
});
after(async function () {
Expand Down
13 changes: 2 additions & 11 deletions packages/truffle/test/scenarios/migrations/production.js
Expand Up @@ -20,11 +20,7 @@ describe("production", function () {
config = await sandbox.create(project);
config.network = "ropsten";
config.logger = logger;
const provider = new Web3.providers.HttpProvider(
"http://localhost:8545",
{ keepAlive: false }
);
web3 = new Web3(provider);
web3 = new Web3("http://localhost:8545");
networkId = await web3.eth.net.getId();
});

Expand Down Expand Up @@ -75,12 +71,7 @@ describe("production", function () {
config = await sandbox.create(project);
config.network = "fakeRopsten";
config.logger = logger;

const provider = new Web3.providers.HttpProvider(
"http://localhost:8545",
{ keepAlive: false }
);
web3 = new Web3(provider);
web3 = new Web3("http://localhost:8545");
networkId = await web3.eth.net.getId();
});

Expand Down
Expand Up @@ -21,7 +21,7 @@ describe("Typescript Tests", () => {
});

describe("testing contract behavior", () => {
it("will run .ts tests and have the correct behavior", async () => {
it("runs .ts tests and have the correct behavior", async () => {
try {
await CommandRunner.run("test test/metacoin.ts", config);
const output = logger.contents();
Expand All @@ -33,7 +33,7 @@ describe("Typescript Tests", () => {
}
}).timeout(70000);

it("will detect and run .sol, .ts, & .js test files", async () => {
it("detects and runs .sol, .ts, & .js test files", async () => {
try {
await CommandRunner.run("test", config);
const output = logger.contents();
Expand Down
19 changes: 19 additions & 0 deletions packages/truffle/test/sources/toyProject/contracts/Migrations.sol
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Migrations {
address public owner = msg.sender;
uint public last_completed_migration;

modifier restricted() {
require(
msg.sender == owner,
"This function is restricted to the contract's owner"
);
_;
}
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
}
@@ -0,0 +1,5 @@
const Migrations = artifacts.require("Migrations");

module.exports = function (deployer) {
deployer.deploy(Migrations);
};
Empty file.
9 changes: 9 additions & 0 deletions packages/truffle/test/sources/toyProject/truffle-config.js
@@ -0,0 +1,9 @@
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*"
}
}
};

0 comments on commit bf8375a

Please sign in to comment.