Skip to content

Commit

Permalink
refactor: removing solc export from core (#520)
Browse files Browse the repository at this point in the history
* refactor: removing solc export from core

* refactor: removing solc from the core package

* refactor: removing openzeppelin contracts dependency
  • Loading branch information
Valazan authored Jan 30, 2024
1 parent e30780e commit 1530094
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 426 deletions.
4 changes: 0 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
},
"dependencies": {
"@ethereumjs/rlp": "^5.0.0",
"@openzeppelin/contracts": "^5.0.1",
"@types/elliptic": "^6.4.18",
"@vechain/vechain-sdk-errors": "*",
"blakejs": "^1.2.1",
"elliptic": "^6.5.4",
"ethers": "6.10.0"
},
"devDependencies": {
"solc": "^0.8.23"
}
}
1 change: 0 additions & 1 deletion packages/core/src/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ export const contract = {
coder
};
export * from './types.d';
export * from '../../tests/contract/compiler';
84 changes: 0 additions & 84 deletions packages/core/tests/contract/compiler.ts

This file was deleted.

98 changes: 9 additions & 89 deletions packages/core/tests/contract/contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { describe, test, expect } from '@jest/globals';
import { compileContract, type Sources } from './compiler';
import { contract, type DeployParams } from '../../src';
import { coder } from '../../src';
import {
compileERC20SampleTokenContract,
compileERC721SampleNFTContract,
getContractSourceCode,
exampleContractAbi,
exampleContractBytecode,
invalidNFTtestCases,
invalidTransferTokenClausesTestCases,
invalidTransferVETtestCases,
Expand All @@ -19,54 +17,39 @@ import {
* @group unit/contract
*/
describe('Contract', () => {
const sources: Sources = {
'Example.sol': {
content: getContractSourceCode(
'tests/contract/sample',
'Example.sol'
)
}
};

test('Build a clause to deploy a contract without constructor', () => {
const compiledContract = compileContract('Example', sources);

const clause = contract.clauseBuilder.deployContract(
compiledContract.bytecode
exampleContractBytecode
);

expect(clause.data).toEqual(compiledContract.bytecode);
expect(clause.data).toEqual(exampleContractBytecode);
expect(clause.to).toBe(null);
expect(clause.value).toBe(0);
});

test('Build a clause to deploy a contract with deploy params', () => {
const compiledContract = compileContract('Example', sources);

const deployParams: DeployParams = {
types: ['uint256'],
values: ['100']
};

const clause = contract.clauseBuilder.deployContract(
compiledContract.bytecode,
exampleContractBytecode,
deployParams
);

// Assertions for various properties of the built transaction.
expect(clause.value).toBe(0);
expect(clause.to).toBe(null);
expect(clause.data.length).toBeGreaterThan(
compiledContract.bytecode.length
exampleContractBytecode.length
);
});

test('Build a clause to call a contract function', () => {
const compiledContract = compileContract('Example', sources);

const clause = contract.clauseBuilder.functionInteraction(
'0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
compiledContract.abi,
exampleContractAbi,
'set',
[1]
);
Expand All @@ -76,75 +59,12 @@ describe('Contract', () => {
expect(clause.data).toBeDefined();
});

/**
* Test to ensure compiling a sample contract and creating an interface from the ABI.
*/
test('Compile a sample contract and create an interface from the abi', () => {
// Compile the contract from a sample file
const contractCompiled = compileContract('Example', sources);

// Ensure the contract compilation is successful
expect(contractCompiled).toBeDefined();

// Create an instance of a Contract interface using the ABI
const contractInterface = coder.createInterface(contractCompiled.abi);

// Ensure the contract interface is created successfully
expect(contractInterface).toBeDefined();
});

/**
* Test compile an ERC20 contract and create an interface from the ABI.
*/
test('Compile an ERC20 contract and create an interface from the abi', () => {
const compiledContract = compileERC20SampleTokenContract();

// Ensure the contract compilation is successful
expect(compiledContract).toBeDefined();
expect(compiledContract.name).toBeDefined();
expect(compiledContract.abi).toBeDefined();
expect(compiledContract.bytecode).toBeDefined();

// Create an instance of a Contract interface using the ABI
const contractInterface = coder.createInterface(compiledContract.abi);

// Ensure the contract interface is created successfully
expect(contractInterface).toBeDefined();
});

/**
* Test compile an ERC721 contract and create an interface from the ABI.
*/
test('Compile an ERC721 contract and create an interface from the abi', () => {
const compiledContract = compileERC721SampleNFTContract();

// Ensure the contract compilation is successful
expect(compiledContract).toBeDefined();
expect(compiledContract.name).toBeDefined();
expect(compiledContract.abi).toBeDefined();
expect(compiledContract.bytecode).toBeDefined();

// Create an instance of a Contract interface using the ABI
const contractInterface = coder.createInterface(compiledContract.abi);

// Ensure the contract interface is created successfully
expect(contractInterface).toBeDefined();
});

/**
* Test compile an ERC20 contract and create an interface from the ABI.
*/
test('Compile the sample NFT contract and create an interface from the abi', () => {
const compiledContract = compileERC20SampleTokenContract();

// Ensure the contract compilation is successful
expect(compiledContract).toBeDefined();
expect(compiledContract.name).toBeDefined();
expect(compiledContract.abi).toBeDefined();
expect(compiledContract.bytecode).toBeDefined();

test('Create an interface from the abi of the sample contract', () => {
// Create an instance of a Contract interface using the ABI
const contractInterface = coder.createInterface(compiledContract.abi);
const contractInterface = coder.createInterface(exampleContractAbi);

// Ensure the contract interface is created successfully
expect(contractInterface).toBeDefined();
Expand Down
Loading

0 comments on commit 1530094

Please sign in to comment.