-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
501af9b
commit f0b500f
Showing
4 changed files
with
153 additions
and
22 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
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 was deleted.
Oops, something went wrong.
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,123 @@ | ||
import anyTest, {TestFn} from 'ava'; | ||
import { Web3 } from 'web3' | ||
import { PluginContextTest } from '@slangroom/core'; | ||
import { astify, execute } from '@slangroom/ethereum'; | ||
|
||
const test = anyTest as TestFn<{web3: Web3}>; | ||
|
||
|
||
test("read the ethereum nonce", async (t) => { | ||
const { ast, errors} = astify('read the ethereum nonce'); | ||
if (errors) { | ||
t.fail(); | ||
return; | ||
} | ||
const ctx = new PluginContextTest('http://78.47.38.223:9485', { | ||
address: "0x2D010920b43aFb54f8d5fB51c9354FbC674b28Fc", | ||
}); | ||
const res = await execute(ctx, ast); | ||
t.deepEqual(res, { | ||
ok: true, | ||
value: '0', | ||
}); | ||
}) | ||
|
||
test("Ethereum gas price", async (t) => { | ||
const { ast, errors} = astify('read the ethereum suggested gas price'); | ||
if (errors) { | ||
t.fail(); | ||
return; | ||
} | ||
const ctx = PluginContextTest.connect('http://78.47.38.223:9485'); | ||
const res = await execute(ctx, ast); | ||
t.truthy(res.ok) | ||
if(res.ok) { | ||
console.log(res.value); | ||
t.is(typeof res.value, 'string'); | ||
} | ||
}) | ||
|
||
test("Retrieve a zenroom object", async (t) => { | ||
const poem = "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000674e656c206d657a7a6f2064656c2063616d6d696e206469206e6f7374726120766974610a6d6920726974726f7661692070657220756e612073656c7661206f73637572612c0a6368c3a9206c612064697269747461207669612065726120736d6172726974612e00000000000000000000000000000000000000000000000000" | ||
const { ast, errors} = astify('read the ethereum bytes'); | ||
if (errors) { | ||
t.fail(); | ||
return; | ||
} | ||
const ctx = new PluginContextTest('http://78.47.38.223:9485', { | ||
transaction_id: '0x0467636a2557a1ccdaf10ce17ee74340096c510acfa9181c85756d43a8bed522' | ||
}); | ||
const res = await execute(ctx, ast); | ||
t.deepEqual(res, { | ||
ok: true, | ||
value: poem, | ||
}); | ||
}) | ||
|
||
test("Ethereum balance", async (t) => { | ||
const { ast, errors } = astify("read the ethereum balance"); | ||
if (errors) { | ||
t.fail(); | ||
return; | ||
} | ||
const ctx = new PluginContextTest('http://78.47.38.223:9485', { | ||
address: "0x2D010920b43aFb54f8d5fB51c9354FbC674b28Fc" | ||
}); | ||
const res = await execute(ctx, ast); | ||
t.deepEqual(res, { | ||
ok: true, | ||
value: "1000000000000000000000", | ||
}); | ||
}) | ||
|
||
test("Read the balance of an array of addresses", async (t) => { | ||
const { ast, errors } = astify("read the Ethereum balance"); | ||
if (errors) { | ||
t.fail(); | ||
return; | ||
} | ||
const ctx = new PluginContextTest('http://78.47.38.223:9485', { | ||
addresses: [ | ||
"0xc32510251F77382bb9214144D2c488408Ec2047C", | ||
"0xFf02577F140557190693cFf549025e66119FEA52", | ||
"0x4743879F5e9dc3fcE41E30380365441E8D14CCEc" | ||
] | ||
}); | ||
const res = await execute(ctx, ast); | ||
t.truthy(res.ok) | ||
if(res.ok) { | ||
for (const v of (res.value as string[])) | ||
t.is(typeof v, "string") | ||
} | ||
}); | ||
/* | ||
test("Ethereum transaction id after broadcast", async (t) => { | ||
const ast = line2Ast("Ethereum transaction id after broadcast of 'signed tx'"); | ||
t.deepEqual(ast.value, { kind: EthereumRequestKind.EthereumBroadcast, rawTransaction: 'signed tx'}) | ||
}) | ||
test("Erc20 method without arg", async (t) => { | ||
const ast = line2Ast("erc20 'symbol' for 'foo'"); | ||
t.deepEqual(ast.value, { kind: EthereumRequestKind.Erc20Method, address: 'foo' }) | ||
}) | ||
test("Erc20 method with arg", async (t) => { | ||
const ast = line2Ast("erc20 'balance' of 'address' for 'foo'"); | ||
t.deepEqual(ast.value, { kind: EthereumRequestKind.Erc20Method, address: 'foo', arg: 'address' }) | ||
}) | ||
test("Erc721 id", async (t) => { | ||
const ast = line2Ast("erc721 id in transaction 'tx id'"); | ||
t.deepEqual(ast.value, { kind: EthereumRequestKind.Erc721Id, transactionId: 'tx id' }) | ||
}) | ||
test("Erc721 asset", async (t) => { | ||
const ast = line2Ast("erc721 asset in 'nft_id' for 'address'"); | ||
t.deepEqual(ast.value, { kind: EthereumRequestKind.Erc721Asset, address: 'address', nftId: 'nft_id' }) | ||
}) | ||
test("Erc721 owner", async (t) => { | ||
const ast = line2Ast("erc721 owner of 'nft_id' for 'address'"); | ||
t.deepEqual(ast.value, { kind: EthereumRequestKind.Erc721Owner, address: 'address', nftId: 'nft_id' }) | ||
}) | ||
*/ |