Skip to content

Compiling contract code in tests #6164

Closed Answered by 0xGh
0xGh asked this question in General Q&A
Aug 20, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

Came up with this solution:

const path = require('path');
const fs = require('fs');

const TruffleCompile = require('@truffle/workflow-compile').default;
const TruffleConfig = require('@truffle/config');
const TruffleContract = require('@truffle/contract');

const MyContractSource = require('fs').readFileSync('./contracts/MyContract.sol', 'utf-8');

let truffleConfig = null;
async function compile(source, fileName = 'TestContract') {
  const config = truffleConfig || TruffleConfig.detect();
  if (!truffleConfig) {
    truffleConfig = config;
  }

  const outFile = path.join('contracts', 'mocks', fileName + '.sol');
  fs.writeFileSync(outFile, source);

  if (config._ && config._.length > 0) 

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@gnidan
Comment options

@0xGh
Comment options

@gnidan
Comment options

Answer selected by gnidan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants