Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge a3c6164 into 91c2526
Browse files Browse the repository at this point in the history
  • Loading branch information
littleskunk committed Jan 17, 2018
2 parents 91c2526 + a3c6164 commit 57d4366
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ addons:
- clang
node_js:
- "6.9.1"
- "8"
before_install:
- export CXX="g++-4.8" CC="gcc-4.8"
after_script:
Expand Down
84 changes: 82 additions & 2 deletions test/client.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,38 @@ describe('Client', function() {
]);
});

it('publishContract', function() {
var client = complex.createClient();
var method = 'publishContract';
var contract = new storj.Contract();
var farmer = storj.Contact({
address: '127.0.0.1',
port: 3030
});
var args = [farmer, contract];
var result = client._serializeRequestArguments(method, args);
expect(result).to.deep.equal([
farmer,
{
audit_count: 10,
data_hash: null,
data_size: 1234,
farmer_id: null,
farmer_signature: null,
payment_destination: null,
payment_download_price: 0,
payment_storage_price: 0,
renter_hd_index: false,
renter_hd_key: false,
renter_id: null,
renter_signature: null,
store_begin: 2000000000,
store_end: 3000000000,
version: 0
}
]);
});

it('getStorageProof', function() {
var client = complex.createClient();
var method = 'getStorageProof';
Expand Down Expand Up @@ -431,8 +463,29 @@ describe('Client', function() {
it('getMirrorNodes', function() {
var client = complex.createClient();
var method = 'getMirrorNodes';
var args = [];
client._serializeRequestArguments(method, args);
var farmer = new storj.Contact({
address: '127.0.0.1',
port: 3030
});
var args = [
farmer
];
var result = client._serializeRequestArguments(method, args);
expect(result).to.equal(args);
});

it('ping', function() {
var client = complex.createClient();
var method = 'ping';
var farmer = new storj.Contact({
address: '127.0.0.1',
port: 3030
});
var args = [
farmer
];
var result = client._serializeRequestArguments(method, args);
expect(result).to.equal(args);
});
});

Expand Down Expand Up @@ -586,6 +639,33 @@ describe('Client', function() {

});

describe('#publishContract', function() {

it('should call send with corrent params', function(done) {
var client = complex.createClient();
client._send = sinon.stub().callsArg(2);
var contract = storj.Contract({});
var farmer1 = storj.Contact({
address: '127.0.0.1',
port: 3030
});
var farmer2 = storj.Contact({
address: '127.0.0.1',
port: 3030
});
client.publishContract([farmer1, farmer2], contract, function() {
expect(client._send.callCount).to.equal(1);
expect(client._send.args[0][0]).to.equal('publishContract');
expect(client._send.args[0][1]).to.deep.equal([
[farmer1, farmer2],
contract
]);
done();
});
});

});

describe('#ping', function() {
it('should call send with correct params', function(done) {
var client = complex.createClient();
Expand Down
41 changes: 38 additions & 3 deletions test/landlord.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,21 +572,56 @@ describe('Landlord', function() {

describe('#_getKeyFromRpcMessage', function() {

it('should use the nodeID of farmer', function() {
it('getConsignmentPointer should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'getConsignmentPointer',
params: [{ nodeID: 'nodeid' }]
})).to.equal('nodeid');
});

it('getRetrievalPointer should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'getRetrievalPointer',
params: [{ nodeID: 'nodeid' }]
})).to.equal('nodeid');
});

it('renewContract should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'renewContract',
params: [{ nodeID: 'nodeid' }]
})).to.equal('nodeid');
});

it('publishContract should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'publishContract',
params: [[{ nodeID: 'nodeid1' }, { nodeID: 'nodeid2' }]]
})).to.equal('nodeid1');
});

it('getStorageProof should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'getStorageProof',
params: [{ nodeID: 'nodeid' }]
})).to.equal('nodeid');
});

it('should use the data hash of contract', function() {
it('ping should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'ping',
params: [{ nodeID: 'nodeid' }]
})).to.equal('nodeid');
});

it('getStorageOffer should use the data hash of contract', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'getStorageOffer',
params: [{ data_hash: 'datahash' }]
})).to.equal('datahash');
});

it('should use the hash of pointer', function() {
it('getMirrorNodes should use the hash of pointer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'getMirrorNodes',
params: [[{ hash: 'datahash' }]]
Expand Down

0 comments on commit 57d4366

Please sign in to comment.