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

Commit

Permalink
Add integration test to verify behavior from bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
cds-amal committed Jul 14, 2021
1 parent e7e0f2f commit 03ae00f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/truffle/test/scenarios/commands/develop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const MemoryLogger = require("../memorylogger");
const CommandRunner = require("../commandrunner");
const path = require("path");
const assert = require("assert");
const Server = require("../server");
const Reporter = require("../reporter");
const sandbox = require("../sandbox");

describe("develop", function () {
let config;
const project = path.join(
__dirname,
"../../sources/develop",
);
const logger = new MemoryLogger();

// before(done => Server.start(done));
// after(done => Server.stop(done));

before(async function () {
this.timeout(10000);
config = await sandbox.create(project);
config.network = "development";
config.logger = logger;
config.mocha = {
reporter: new Reporter(logger),
};
});

it("should load snippets", async function () {
this.timeout(70000);

await CommandRunner.run("develop", config);
const output = logger.contents();

//prepare a helpful message to standout in CI log noise
const formatLines = (lines) =>
lines.split("\n").map((line) => `\t---truffle develop log---\t${line}`)
.join("\n");
const successMessage = "Snippet Loaded";
assert(
output.includes(successMessage),
`Expected "${successMessage}" in output:\n${formatLines(output)}`,
);
});
});
23 changes: 23 additions & 0 deletions packages/truffle/test/sources/develop/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity ^0.5.0;

contract Migrations {
address public owner;
uint public last_completed_migration;

constructor() public {
owner = msg.sender;
}

modifier restricted() {
if (msg.sender == owner) _;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
3 changes: 3 additions & 0 deletions packages/truffle/test/sources/develop/contracts/contract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pragma solidity ^0.5.0;

contract Contract { }
8 changes: 8 additions & 0 deletions packages/truffle/test/sources/develop/snippets/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const main = () => {
console.log("Snippet Loaded");

// todo: might need to allow some time for io flush
setTimeout(() => process.exit(0), 0);
}

main();
16 changes: 16 additions & 0 deletions packages/truffle/test/sources/develop/truffle-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
networks: {
local: {
host: "127.0.0.1",
port: 8545,
network_id: "*",
gas: 4700000,
gasPrice: 20000000000
}
},
console: {
require: [
{ path: "./snippets/helper.js" }
]
}
};

0 comments on commit 03ae00f

Please sign in to comment.