Skip to content

Commit

Permalink
Merge pull request #24 from Lamden/contract-variables-endpoint
Browse files Browse the repository at this point in the history
added get variables masternode endpoint to the Masternode_API
  • Loading branch information
JeffWScott authored Jan 13, 2021
2 parents e0e728b + 902fae2 commit f4a63c5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions dist/lamden.js
Original file line number Diff line number Diff line change
Expand Up @@ -5562,6 +5562,16 @@ class LamdenMasterNode_API{

}

async getContractVariables(contract){
let path = `/contracts/${contract}/variables`;
return this.send('GET', path, {}, undefined, (res, err) => {
try{
if (res.variables) return res
} catch (e){}
return {};
})
}

async pingServer(){
return this.send('GET', '/ping', {}, undefined, (res, err) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lamden-js",
"version": "1.3.5",
"version": "1.3.6",
"description": "A javascript implementaion for creating wallets, submitting transactions and interacting with masternodes on the Lamden Blockchain.",
"main": "dist/lamden.js",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions src/js/masternode-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ export class LamdenMasterNode_API{

}

async getContractVariables(contract){
let path = `/contracts/${contract}/variables`
return this.send('GET', path, {}, undefined, (res, err) => {
try{
if (res.variables) return res
} catch (e){}
return {};
})
}

async pingServer(){
return this.send('GET', '/ping', {}, undefined, (res, err) => {
try {
Expand Down
21 changes: 21 additions & 0 deletions test/masternode_api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ describe('Test Masternode API returns', () => {
})
})

context('Masternode_API.getContractVariables()', () => {
it('returns an array if a contract exists on the blockchain', async () => {
let response = await goodNetwork_api.getContractVariables('currency')
expect(Array.isArray(response.variables)).to.be(true);
expect(Array.isArray(response.hashes)).to.be(true);
expect(response.hashes.length > 0).to.be(true);
})
it('returns an empty Object if a contract does not exist on the blockchain', async () => {
let response = await goodNetwork_api.getContractVariables(wallet.new_wallet().vk)
expect(Array.isArray(response.variables)).to.be(false);
expect(Array.isArray(response.hashes)).to.be(false);
expect(Object.keys(response).length === 0).to.be(true);
})
it('returns empty Object if provided network is unresponsive', async () => {
let response = await badNetwork_api.getContractVariables('currency')
expect(Array.isArray(response.variables)).to.be(false);
expect(Array.isArray(response.hashes)).to.be(false);
expect(Object.keys(response).length === 0).to.be(true);
})
})

context('Masternode_API.getVariable()', () => {
it('returns the value of the variable if the key exists', async () => {
let key = balanceCheckWallet.float;
Expand Down

0 comments on commit f4a63c5

Please sign in to comment.