generate file working

pull/1862/head
Aniket-Engg 3 years ago committed by Aniket
parent 93af567fa9
commit 3c0ce77009
  1. 26
      libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts

@ -49,7 +49,9 @@ export class TestTabLogic {
const fileNameToImport = (!hasCurrent) ? fileName : this.currentPath + '/' + splittedFileName[splittedFileName.length - 1] const fileNameToImport = (!hasCurrent) ? fileName : this.currentPath + '/' + splittedFileName[splittedFileName.length - 1]
this.helper.createNonClashingNameWithPrefix(fileNameToImport, fileProvider, '_test', (error: any, newFile: any) => { this.helper.createNonClashingNameWithPrefix(fileNameToImport, fileProvider, '_test', (error: any, newFile: any) => {
// if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) // if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error)
// if (!fileProvider.set(newFile, this.generateTestContractSample(hasCurrent, fileName))) return modalDialogCustom.alert('Failed to create test file ' + newFile) const isFileCreated = fileProvider.set(newFile, this.generateTestContractSample(hasCurrent, fileName))
console.log('isFileCreated---->', isFileCreated)
// if (!isFileCreated) return modalDialogCustom.alert('Failed to create test file ' + newFile)
this.fileManager.open(newFile) this.fileManager.open(newFile)
this.fileManager.syncEditor(newFile) this.fileManager.syncEditor(newFile)
}) })
@ -89,19 +91,19 @@ export class TestTabLogic {
const comment = hasCurrent ? `import "${relative}/${remixPath.basename(fileToImport)}";` : '// <import file to test>' const comment = hasCurrent ? `import "${relative}/${remixPath.basename(fileToImport)}";` : '// <import file to test>'
return `// SPDX-License-Identifier: GPL-3.0 return `// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0; pragma solidity >=0.4.22 <0.9.0;
// This import is automatically injected by Remix // This import is automatically injected by Remix
import "remix_tests.sol"; import "remix_tests.sol";
// This import is required to use custom transaction context // This import is required to use custom transaction context
// Although it may fail compilation in 'Solidity Compiler' plugin // Although it may fail compilation in 'Solidity Compiler' plugin
// But it will work fine in 'Solidity Unit Testing' plugin // But it will work fine in 'Solidity Unit Testing' plugin
import "remix_accounts.sol"; import "remix_accounts.sol";
${comment} ${comment}
// File name has to end with '_test.sol', this file can contain more than one testSuite contracts // File name has to end with '_test.sol', this file can contain more than one testSuite contracts
contract ${contractName} { contract ${contractName} {
/// 'beforeAll' runs before all other tests /// 'beforeAll' runs before all other tests
/// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll' /// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll'
@ -134,7 +136,7 @@ export class TestTabLogic {
Assert.equal(msg.sender, TestsAccounts.getAccount(1), "Invalid sender"); Assert.equal(msg.sender, TestsAccounts.getAccount(1), "Invalid sender");
Assert.equal(msg.value, 100, "Invalid value"); Assert.equal(msg.value, 100, "Invalid value");
} }
} }
` `
} }
} }

Loading…
Cancel
Save