Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/node utf 8 test #21

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions test/integration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ describe('Integration test on ClientService', async () => {
const mockedContractName = 'com.org1.contract.StateUpdater';
const mockedFunctionName = 'com.org1.function.TestFunction';
const mockedAssetId = `mockedAssetId${Date.now()}`;
const mockedNonAsciiAssetId = `国家标准_ふーバル_情報銀行_정보은행_ƣƢƠ_ஞண${Date.now()}`;
const mockedState = 1;
const mockedContractArgument = {
asset_id: mockedAssetId,
state: mockedState,
};
const nonAsciiContractArgument = {
asset_id: mockedNonAsciiAssetId,
state: mockedState,
};
const contractProperty = {
properties: 'bar',
};
Expand Down Expand Up @@ -133,6 +138,18 @@ describe('Integration test on ClientService', async () => {
assert.equal(contractResult.properties,
contractProperty.properties);
});
it('should work as expected when executing a registered contract with non-ascii character',
async () => {
const response = await clientService.executeContract(
mockedContractId,
nonAsciiContractArgument, {});

const contractResult = response.result;
assert.equal(contractResult.asset_id, nonAsciiContractArgument.asset_id);
assert.equal(contractResult.state, mockedState);
assert.equal(contractResult.properties,
contractProperty.properties);
});

it('should execute the function properly and cassandra' +
'query should return proper object when correct inputs are specified',
Expand All @@ -142,19 +159,37 @@ describe('Integration test on ClientService', async () => {
state: Date.now(),
_functions_: [mockedFunctionId],
};
const contractNonAsciiArgumentWithFunction = {
asset_id: mockedNonAsciiAssetId,
state: Date.now(),
_functions_: [mockedFunctionId],
};
const mockedFunctionArgument = {
asset_id: mockedAssetId,
state: mockedState,
};
const mockedNonAsciiFunctionArgument = {
asset_id: mockedNonAsciiAssetId,
state: mockedState,
};
const response = await clientService.executeContract(
mockedContractId,
contractArgumentWithFunction,
mockedFunctionArgument,
);
const responseNonAscii = await clientService.executeContract(
mockedContractId,
contractNonAsciiArgumentWithFunction,
mockedNonAsciiFunctionArgument,
);
assert.equal(
response.getResult().state,
contractArgumentWithFunction.state,
);
assert.equal(
responseNonAscii.getResult().state,
contractNonAsciiArgumentWithFunction.state,
);
cassandraClient = new cassandra.Client({
contactPoints: ['127.0.0.1:9042'],
localDataCenter: 'datacenter1',
Expand Down
33 changes: 33 additions & 0 deletions test/integration_test_binary_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,16 @@ const mockedContractId = `StateUpdater${Date.now()}`;
const mockedContractName = 'com.org1.contract.StateUpdater';
const mockedFunctionName = 'com.org1.function.TestFunction';
const mockedAssetId = `mockedAssetId${Date.now()}`;
const mockedNonAsciiAssetId = `国家标准_ふーバル_情報銀行_정보은행_ƣƢƠ_ஞண${Date.now()}`;
const mockedState = 1;
const mockedContractArgument = {
asset_id: mockedAssetId,
state: mockedState,
};
const nonAsciiContractArgument = {
asset_id: mockedNonAsciiAssetId,
state: mockedState,
};
const contractProperty = {
properties: 'bar',
};
Expand Down Expand Up @@ -217,6 +222,20 @@ describe('Integration test on ClientServiceWithBinary', async () => {
assert.equal(result.properties, contractProperty.properties);
},
);
it('should work as expected when executing a registered contract with non-ascii character',
async () => {
const binary =
await clientService.createSerializedContractExecutionRequest(
mockedContractId,
nonAsciiContractArgument, {});

const response = await clientService.executeContract(binary);
const contractResult = response.result;
assert.equal(contractResult.asset_id, nonAsciiContractArgument.asset_id);
assert.equal(contractResult.state, mockedState);
assert.equal(contractResult.properties,
contractProperty.properties);
});
it('should get error if contract id does exist',
async () => {
const binary =
Expand Down Expand Up @@ -247,6 +266,11 @@ describe('Integration test on ClientServiceWithBinary', async () => {
state: Date.now(),
_functions_: [mockedFunctionId],
};
const contractNonAsciiArgumentWithFunction = {
asset_id: mockedNonAsciiAssetId,
state: Date.now(),
_functions_: [mockedFunctionId],
};
const mockedFunctionArgument = {
asset_id: mockedAssetId,
state: mockedState,
Expand All @@ -257,8 +281,16 @@ describe('Integration test on ClientServiceWithBinary', async () => {
contractArgumentWithFunction,
mockedFunctionArgument,
);
const nonAsciiBinary =
await clientService.createSerializedContractExecutionRequest(
mockedContractId,
contractNonAsciiArgumentWithFunction,
mockedFunctionArgument,
);
const response = await clientService.executeContract(binary);
const result = response.getResult();
const nonAsciiResponse = await clientService.executeContract(nonAsciiBinary);
const nonAsciiResult = nonAsciiResponse.getResult();

const cassandraClient = new cassandra.Client({
contactPoints: ['127.0.0.1:9042'],
Expand All @@ -269,6 +301,7 @@ describe('Integration test on ClientServiceWithBinary', async () => {
);

assert.equal(result.state, contractArgumentWithFunction.state);
assert.equal(nonAsciiResult.state, contractArgumentWithFunction.state);
assert.equal(
cassandraResponse.rows[0].column_a,
contractArgumentWithFunction.asset_id,
Expand Down