Skip to content

Commit

Permalink
tests for truffle project
Browse files Browse the repository at this point in the history
  • Loading branch information
antico5 committed Feb 14, 2023
1 parent e527b24 commit 50dba43
Show file tree
Hide file tree
Showing 22 changed files with 778 additions and 12 deletions.
16 changes: 4 additions & 12 deletions server/src/frameworks/Truffle/TruffleProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* eslint-disable no-empty */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { execSync } from "child_process";
import { existsSync } from "fs";
import _ from "lodash";
import path from "path";
import semver from "semver";
Expand Down Expand Up @@ -110,24 +111,15 @@ export class TruffleProject extends Project {
file: string,
importPath: string
): Promise<string | undefined> {
// const resolver = new Resolver({
// contracts_directory: this.sourcesPath,
// working_directory: this.basePath,
// contracts_build_directory: path.join(this.basePath, "build"),
// });

// const resolved = resolver.resolve(importPath, file);

// console.log(`(${file},${importPath}) => ${resolved}`);

// Absolute path
if (path.isAbsolute(importPath)) {
return importPath;
return existsSync(importPath) ? importPath : undefined;
}

// Relative path
if (importPath.startsWith(".") || importPath.startsWith("..")) {
return path.resolve(path.dirname(file), importPath);
const resolvedPath = path.resolve(path.dirname(file), importPath);
return existsSync(resolvedPath) ? resolvedPath : undefined;
}

// Truffle direct imports
Expand Down
1 change: 1 addition & 0 deletions test/protocol/projects/truffle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pragma solidity 0.8.8;

contract Foo {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '';
Empty file.
Empty file.
57 changes: 57 additions & 0 deletions test/protocol/projects/truffle/my_contracts/definition/Test.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;

interface ABV {
function giveVote(address voter) external;
function delegate(address to) external;
}

contract Test is ABV {
struct Voter {
bool voted;
address delegate;
}

mapping(address => Voter) public voters;
Proposal[] public proposals;

constructor(bytes32[] memory proposalNames) {
Proposal memory p;
for (uint i = 0; i < proposalNames.length; i++) {
( p, ) = newProposalAndVoter(proposalNames[i], false, msg.sender);
proposals.push(p);
}
}

function giveVote(address voter) public virtual override {
voters[voter].voted = true;
}

function giveVoteAndDelegate(address voter, address to) public {
giveVote(voter);
delegate(to);
}

function delegate(address to) public virtual override {
voters[msg.sender].delegate = to;
}

function newProposalAndVoter(bytes32 name, bool voted, address delegateTo) public pure returns (Proposal memory p, Voter memory v) {
p = Proposal({
name: name
});

v = Voter({
voted: voted,
delegate: delegateTo
});
}

function getLastProposalName() public view returns (bytes32 name) {
name = proposals[proposals.length - 1].name;
}

struct Proposal {
bytes32 name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.8;

import './NonExistent.sol';

contract Foo {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.8;

contract Foo {
string public name = "Foo"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;

interface ABV {
function giveVote(address voter) external;
function delegate(address to) external;
}

contract Test is ABV {
struct Voter {
bool voted;
address delegate;
}

mapping(address => Voter) public voters;
Proposal[] public proposals;

constructor(bytes32[] memory proposalNames) {
Proposal memory p;
for (uint i = 0; i < proposalNames.length; i++) {
( p, ) = newProposalAndVoter(proposalNames[i], false, msg.sender);
proposals.push(p);
}
}

function giveVote(address voter) public virtual override {
voters[voter].voted = true;
}

function giveVoteAndDelegate(address voter, address to) public {
giveVote(voter);
delegate(to);
}

function delegate(address to) public virtual override {
voters[msg.sender].delegate = to;
}

function newProposalAndVoter(bytes32 name, bool voted, address delegateTo) public pure returns (Proposal memory p, Voter memory v) {
p = Proposal({
name: name
});

v = Voter({
voted: voted,
delegate: delegateTo
});
}

function getLastProposalName() public view returns (bytes32 name) {
name = proposals[proposals.length - 1].name;
}

struct Proposal {
bytes32 name;
}
}
57 changes: 57 additions & 0 deletions test/protocol/projects/truffle/my_contracts/references/Test.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;

interface ABV {
function giveVote(address voter) external;
function delegate(address to) external;
}

contract Test is ABV {
struct Voter {
bool voted;
address delegate;
}

mapping(address => Voter) public voters;
Proposal[] public proposals;

constructor(bytes32[] memory proposalNames) {
Proposal memory p;
for (uint i = 0; i < proposalNames.length; i++) {
( p, ) = newProposalAndVoter(proposalNames[i], false, msg.sender);
proposals.push(p);
}
}

function giveVote(address voter) public virtual override {
voters[voter].voted = true;
}

function giveVoteAndDelegate(address voter, address to) public {
giveVote(voter);
delegate(to);
}

function delegate(address to) public virtual override {
voters[msg.sender].delegate = to;
}

function newProposalAndVoter(bytes32 name, bool voted, address delegateTo) public pure returns (Proposal memory p, Voter memory v) {
p = Proposal({
name: name
});

v = Voter({
voted: voted,
delegate: delegateTo
});
}

function getLastProposalName() public view returns (bytes32 name) {
name = proposals[proposals.length - 1].name;
}

struct Proposal {
bytes32 name;
}
}
57 changes: 57 additions & 0 deletions test/protocol/projects/truffle/my_contracts/rename/Test.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;

interface ABV {
function giveVote(address voter) external;
function delegate(address to) external;
}

contract Test is ABV {
struct Voter {
bool voted;
address delegate;
}

mapping(address => Voter) public voters;
Proposal[] public proposals;

constructor(bytes32[] memory proposalNames) {
Proposal memory p;
for (uint i = 0; i < proposalNames.length; i++) {
( p, ) = newProposalAndVoter(proposalNames[i], false, msg.sender);
proposals.push(p);
}
}

function giveVote(address voter) public virtual override {
voters[voter].voted = true;
}

function giveVoteAndDelegate(address voter, address to) public {
giveVote(voter);
delegate(to);
}

function delegate(address to) public virtual override {
voters[msg.sender].delegate = to;
}

function newProposalAndVoter(bytes32 name, bool voted, address delegateTo) public pure returns (Proposal memory p, Voter memory v) {
p = Proposal({
name: name
});

v = Voter({
voted: voted,
delegate: delegateTo
});
}

function getLastProposalName() public view returns (bytes32 name) {
name = proposals[proposals.length - 1].name;
}

struct Proposal {
bytes32 name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;

interface ABV {
function giveVote(address voter) external;
function delegate(address to) external;
}

contract Test is ABV {
struct Voter {
bool voted;
address delegate;
}

mapping(address => Voter) public voters;
Proposal[] public proposals;

constructor(bytes32[] memory proposalNames) {
Proposal memory p;
for (uint i = 0; i < proposalNames.length; i++) {
( p, ) = newProposalAndVoter(proposalNames[i], false, msg.sender);
proposals.push(p);
}
}

function giveVote(address voter) public virtual override {
voters[voter].voted = true;
}

function giveVoteAndDelegate(address voter, address to) public {
giveVote(voter);
delegate(to);
}

function delegate(address to) public virtual override {
voters[msg.sender].delegate = to;
}

function newProposalAndVoter(bytes32 name, bool voted, address delegateTo) public pure returns (Proposal memory p, Voter memory v) {
p = Proposal({
name: name
});

v = Voter({
voted: voted,
delegate: delegateTo
});
}

function getLastProposalName() public view returns (bytes32 name) {
name = proposals[proposals.length - 1].name;
}

struct Proposal {
bytes32 name;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/protocol/projects/truffle/truffle-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
contracts_directory: 'my_contracts',
compilers: {
solc: {
version: '0.8.8', // Fetch exact version from solc-bin
// settings: {
// remappings: ["oz=node_modules/@openzeppelin"],
// },
},
},
}
Loading

0 comments on commit 50dba43

Please sign in to comment.