-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd4b649
commit 7cf1b49
Showing
5 changed files
with
74 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"KT1UvS7eBoNoP7qmGkfPtTGM7s7pYxLnkUzR-/v2/data/tezos/mainnet/accounts": [ { | ||
"block_level": 655361, | ||
"is_activated": false, | ||
"balance": 0, | ||
"is_baker": false, | ||
"delegate_value": null, | ||
"spendable": null, | ||
"account_id": "KT1UvS7eBoNoP7qmGkfPtTGM7s7pYxLnkUzR", | ||
"manager": null, | ||
"storage": "\"hello\"", | ||
"counter": null, | ||
"block_id": "BLu2kYLJuELGnxqeX1DCKWsnAy6kM3Qii563Ja9nkPtqy3iSCaf", | ||
"script": "parameter string;\nstorage string;\ncode { CAR ;\n NIL operation ;\n PAIR }", | ||
"delegate_setable": null | ||
} ] | ||
} |
93 changes: 34 additions & 59 deletions
93
ConseilJS-core/test/chain/tezos/TezosContractIntrospector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,39 @@ | ||
import { expect } from 'chai'; | ||
import { expect, use } from "chai"; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import nock from 'nock'; | ||
import fetch from 'node-fetch'; | ||
import * as log from 'loglevel'; | ||
|
||
import { TezosContractIntrospector } from '../../../src/chain/tezos/TezosContractIntrospector'; | ||
import { Parameter, EntryPoint } from '../../../src/types/tezos/ContractIntrospectionTypes'; | ||
|
||
|
||
describe("Generate EntryPoints From Params", () => { | ||
it('multi-sig', async () => { // https://github.com/murbard/smart-contracts/blob/master/multisig/michelson/multisig.tz as of 2019/dec/30 | ||
const entryPoints = await TezosContractIntrospector.generateEntryPointsFromParams(`parameter | ||
(pair | ||
(pair :payload | ||
(nat %counter) # counter, used to prevent replay attacks | ||
(or :action # payload to sign, represents the requested action | ||
(pair :transfer # transfer tokens | ||
(mutez %amount) # amount to transfer | ||
(contract %dest unit)) # destination to transfer to | ||
(or | ||
(option %delegate key_hash) # change the delegate to this address | ||
(pair %change_keys # change the keys controlling the multisig | ||
(nat %threshold) # new threshold | ||
(list %keys key))))) # new list of keys | ||
(list %sigs (option signature))); # signatures`); | ||
|
||
entryPoints.forEach(e => { | ||
console.log(formatEntryPoint(e)); | ||
//console.log(`invocation pattern: ${e.generateInvocationString()}`); | ||
console.log(`invocation pattern: ${e.generateSampleInvocation()}`); | ||
}); | ||
import { registerFetch, registerLogger } from '../../../src/index'; | ||
|
||
expect(entryPoints.length).to.be.greaterThan(0); | ||
}); | ||
import mochaAsync from '../../mochaTestHelper'; | ||
import * as responses from "../../_staticData/ConseilResponses.json"; | ||
|
||
/*it('generic multi-sig', async () => { // https://github.com/murbard/smart-contracts/blob/master/multisig/michelson/generic.tz as of 2019/dec/30 | ||
const entryPoints = await TezosContractIntrospector.generateEntryPointsFromParams(`parameter | ||
(or | ||
(unit %default) | ||
(pair %main | ||
(pair :payload | ||
(nat %counter) # counter, used to prevent replay attacks | ||
(or :action # payload to sign, represents the requested action | ||
(lambda %operation unit (list operation)) | ||
(pair %change_keys # change the keys controlling the multisig | ||
(nat %threshold) # new threshold | ||
(list %keys key)))) # new list of keys | ||
(list %sigs (option signature)))); # signatures`); | ||
entryPoints.forEach(e => { | ||
console.log(`\n${e.name + '(' + e.parameters.map(p => p.type + ' ' + p.name).join(', ') + ')'}`) | ||
//console.log(`invocation pattern: ${e.generateInvocationString()}`); | ||
console.log(`invocation pattern: ${e.generateSampleInvocation()}`); | ||
}); | ||
import { TezosContractIntrospector } from '../../../src/chain/tezos/TezosContractIntrospector'; | ||
|
||
expect(entryPoints.length).to.be.greaterThan(0); | ||
});*/ | ||
use(chaiAsPromised); | ||
|
||
describe("TezosContractIntrospector test", () => { | ||
const serverConfig = { url: 'https://conseil.server', apiKey: 'key', network: 'mainnet' }; | ||
|
||
before(mochaAsync(async () => { | ||
const logger = log.getLogger('conseiljs'); | ||
logger.setLevel('error', false); | ||
registerLogger(logger); | ||
registerFetch(fetch); | ||
})); | ||
|
||
it('getAccountForBlock test', mochaAsync(async () => { | ||
const server = nock(serverConfig.url); | ||
server | ||
.filteringRequestBody(body => '*') | ||
.post(`/v2/data/tezos/mainnet/accounts`) | ||
.reply(200, responses['KT1UvS7eBoNoP7qmGkfPtTGM7s7pYxLnkUzR-/v2/data/tezos/mainnet/accounts']); | ||
|
||
const result = await TezosContractIntrospector.generateEntryPointsFromAddress(serverConfig, 'mainnet', 'KT1UvS7eBoNoP7qmGkfPtTGM7s7pYxLnkUzR'); | ||
|
||
expect(result).to.exist; | ||
expect(result.length).to.equal(1); | ||
expect(result[0].name).to.equal('default'); | ||
})); | ||
}); | ||
|
||
function formatEntryPoint(e: EntryPoint) { | ||
let s = ''; | ||
s += !!e.name ? e.name : ''; | ||
s += '('; | ||
s += e.parameters.map(p => p.type + (!!p.name ? ` ${p.name}`: '')).join(', '); | ||
s += ')'; | ||
return s; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters