Skip to content

Commit

Permalink
feat(bridge): ✨ should add same for ICONContractAdater and EOSContrac…
Browse files Browse the repository at this point in the history
…tAdapter (#71)
  • Loading branch information
boomspeed94 authored and cymonkey committed Nov 20, 2020
1 parent 21460c0 commit f2fcf20
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/bridge/src/eos/EOSContractAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export class EOSContractAdapter extends AbsContractAdapter {
}

this.typeInterpreter = new EOSTypeInterpreter();
this.templatePath = path.resolve(this.templatePath, this.blockchainType);
}

generateFromTemplate() {
this.templatePath = path.resolve(this.templatePath, this.blockchainType);

if (!this.templatePath) throw new Error('Template path not found');
this.actionCreators = [new EOSCreAction(), new EOSUpdAction(), new EOSDelAction()];
this.actionCreators.forEach(ac => {
ac.templatePath = this.templatePath;
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge/src/icon/ICONContractAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ export class ICONContractAdapter extends AbsContractAdapter {
this.blockchainType = 'icon';
}
this.typeInterpreter = new ICONTypeInterpreter();
this.templatePath = path.resolve(this.templatePath, this.blockchainType);
}

generateFromTemplate() {
if (!this.templatePath) throw new Error('Template path not found');
this.pyFilePrinter = new FilePrinter(this.outputPath, new PythonPrettier(), this.logger);
this.jsFilePrinter = new FilePrinter(this.outputPath, new JsPrettier(), this.logger);

// this.coder = new FileCoder(this.outputPath, new CplusplusPrettier(), this.logger);

this.templatePath = path.resolve(this.templatePath, this.blockchainType);

this.generateInit();
this.generatePackage();
this.generateMainPy();
Expand Down
22 changes: 13 additions & 9 deletions packages/bridge/test/eos/EOSContractAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('test EOS contract addapter', () => {
expect(adapter.templatePath).toEqual(
path.resolve(
path.dirname(require.resolve('@aloxide/bridge')),
'../smart-contract-templates',
'../smart-contract-templates/' + adapter.blockchainType,
),
);

Expand All @@ -72,15 +72,24 @@ describe('test EOS contract addapter', () => {
});
});
describe('test generateFromTemplate', () => {
it('should update templatePath to specific blockchain', () => {
it('should throw exception when template is null', () => {
const adapter = new EOSContractAdapter();
adapter.entityConfigs = entityConfigs;
adapter.logger = {
info: jest.fn(),
debug: jest.fn(),
};
adapter.templatePath = null;
expect(() => adapter.generateFromTemplate()).toThrowError('Template path not found');
});

it('should generateFromTemplate', () => {
const adapter = new EOSContractAdapter();
adapter.entityConfigs = entityConfigs;
adapter.logger = {
info: jest.fn(),
debug: jest.fn(),
};
const templatePath = path.resolve(__dirname, '../../smart-contract-templates');
adapter.templatePath = templatePath;

const createTables = jest.spyOn(adapter, 'createTables');
createTables.mockImplementation(jest.fn());
Expand All @@ -95,7 +104,6 @@ describe('test EOS contract addapter', () => {
spyGenerateHpp.mockImplementation(jest.fn());

adapter.generateFromTemplate();
expect(adapter.templatePath).toEqual(path.resolve(templatePath, blockchain));

expect(createActions).toBeCalledTimes(1);
expect(createActions).toBeCalledTimes(1);
Expand All @@ -111,9 +119,6 @@ describe('test EOS contract addapter', () => {
debug: jest.fn(),
};

const templatePath = 'test-path';
adapter.templatePath = templatePath;

const createTables = jest.spyOn(adapter, 'createTables');
createTables.mockImplementation(jest.fn());

Expand All @@ -131,7 +136,6 @@ describe('test EOS contract addapter', () => {
spyCompile.mockReturnValue(template);

adapter.generateFromTemplate();
expect(adapter.templatePath).toEqual(path.resolve(templatePath, blockchain));

expect(createActions).toBeCalledTimes(1);
expect(createActions).toBeCalledTimes(1);
Expand Down
18 changes: 13 additions & 5 deletions packages/bridge/test/icon/ICONContractAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('test ICON contract addapter', () => {
expect(adapter.templatePath).toEqual(
path.resolve(
path.dirname(require.resolve('@aloxide/bridge')),
'../smart-contract-templates',
'../smart-contract-templates/' + adapter.blockchainType,
),
);

Expand All @@ -85,15 +85,24 @@ describe('test ICON contract addapter', () => {
});
});
describe('test generateFromTemplate', () => {
it('should update templatePath to specific blockchain', () => {
it('should throw error when template path does not exist', () => {
const adapter = new ICONContractAdapter();
adapter.entityConfigs = entityConfigs;
adapter.logger = {
info: jest.fn(),
debug: jest.fn(),
};
adapter.templatePath = null;
expect(() => adapter.generateFromTemplate()).toThrowError('Template path not found');
});

it('generateFromTemplate', () => {
const adapter = new ICONContractAdapter();
adapter.entityConfigs = entityConfigs;
adapter.logger = {
info: jest.fn(),
debug: jest.fn(),
};
const templatePath = 'test-path';
adapter.templatePath = templatePath;

const spyGenerateInit = jest.spyOn(adapter, 'generateInit');
spyGenerateInit.mockImplementation(jest.fn());
Expand All @@ -111,7 +120,6 @@ describe('test ICON contract addapter', () => {
spyGenerateTXAPI.mockImplementation(jest.fn());

adapter.generateFromTemplate();
expect(adapter.templatePath).toEqual(path.resolve(templatePath, blockchain));

expect(spyGenerateInit).toBeCalledTimes(1);
expect(spyGeneratePackage).toBeCalledTimes(1);
Expand Down

0 comments on commit f2fcf20

Please sign in to comment.