Add tests for ENS (#1933)

* add basic test to ens

* add more tests

* test arguments for test
This commit is contained in:
Jonathan Rainville 2019-10-11 22:42:16 -04:00 committed by Iuri Matias
parent 3f65077268
commit 6f90099d47
2 changed files with 95 additions and 4 deletions

View File

@ -36,10 +36,8 @@
"lint": "eslint src/", "lint": "eslint src/",
"qa": "npm-run-all lint _build", "qa": "npm-run-all lint _build",
"reset": "npx rimraf dist embark-*.tgz package", "reset": "npx rimraf dist embark-*.tgz package",
"solo": "embark-solo" "solo": "embark-solo",
}, "test": "jest"
"eslintConfig": {
"extends": "../../../.eslintrc.json"
}, },
"dependencies": { "dependencies": {
"@babel/runtime-corejs2": "7.6.2", "@babel/runtime-corejs2": "7.6.2",
@ -54,10 +52,33 @@
}, },
"devDependencies": { "devDependencies": {
"embark-solo": "^4.1.1", "embark-solo": "^4.1.1",
"babel-eslint": "10.0.3",
"babel-jest": "24.9.0",
"eslint": "5.7.0", "eslint": "5.7.0",
"eslint-plugin-jest": "22.5.1",
"jest": "24.9.0",
"npm-run-all": "4.1.5", "npm-run-all": "4.1.5",
"rimraf": "3.0.0" "rimraf": "3.0.0"
}, },
"eslintConfig": {
"env": {
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:jest/recommended",
"plugin:jest/style"
],
"parser": "babel-eslint"
},
"jest": {
"collectCoverage": true,
"testEnvironment": "node",
"testMatch": [
"**/test/**/*.js"
]
},
"engines": { "engines": {
"node": ">=8.12.0 <12.0.0", "node": ">=8.12.0 <12.0.0",
"npm": ">=6.4.1", "npm": ">=6.4.1",

View File

@ -0,0 +1,70 @@
const ENS = require("../dist/index");
const { fakeEmbark } = require('embark-testing');
const {Utils} = require('embarkjs');
const secureSend = Utils.secureSend;
describe('embark-ens', () => {
let ens, doneCb;
const { embark } = fakeEmbark();
beforeEach(() => {
embark.events.setCommandHandler('namesystem:node:register', () => {});
ens = new ENS(embark);
ens.config = {
embarkConfig: {
generationDir: 'test-dir'
},
namesystemConfig: {
register: {
rootDomain: 'root.eth'
}
}
};
});
afterEach(() => {
embark.teardown();
});
it("should register the right artifact", (done) => {
const pipelineRegisterHandler = jest.fn((args, cb) => {
expect(args).toEqual({
path: ['test-dir', 'config'],
file: 'namesystem.json',
format: 'json',
content: Object.assign({}, embark.config.namesystemConfig, ens.getEnsConfig())
});
cb();
done();
});
ens.getEnsConfig = jest.fn();
embark.events.setCommandHandler('pipeline:register', pipelineRegisterHandler);
ens.addArtifactFile({}, () => {});
});
describe('safeRegisterSubDomain', () => {
it('should register if the name is not registered', (done) => {
ens.ensResolve = jest.fn((name, cb) => {cb(null, null)});
ens.registerSubDomain = jest.fn((defaultAccount, subDomainName, reverseNode, address, secureSend, callback) => callback());
ens.safeRegisterSubDomain('test.eth', '0x0123', '0x4321', () => {
expect(ens.registerSubDomain).toHaveBeenCalledWith('0x4321', 'test.eth', '0xd523d7aaff8eefa323a17f2c79662ff1a8d952f6fa9cf53986347e99ada8098c', '0x0123', secureSend, expect.any(Function));
done();
});
});
it('should not register if the name is already registered', (done) => {
ens.ensResolve = jest.fn((name, cb) => {cb(null, '0x0123')});
ens.registerSubDomain = jest.fn((defaultAccount, subDomainName, reverseNode, address, secureSend, callback) => callback());
ens.safeRegisterSubDomain('test.eth', '0x0123', '0x4321', () => {
expect(ens.registerSubDomain).not.toHaveBeenCalled();
done();
});
});
});
});