-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use single gateway * Addition of placeholders * Completed first getPastEvents test * Addition * Placeholders * Addition * Addition
- Loading branch information
1 parent
d5af8f6
commit 119478a
Showing
23 changed files
with
531 additions
and
20 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 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<pysystest type="auto"> | ||
|
||
<description> | ||
<title>Visibility Config: subscribe, public event, one EOA in event can view</title> | ||
<purpose><![CDATA[ | ||
]]> | ||
</purpose> | ||
</description> | ||
|
||
<classification> | ||
<groups inherit="true"> | ||
<group>skip</group> | ||
<group>vis_config</group> | ||
</groups> | ||
<modes inherit="true"> | ||
<mode>ten.sepolia</mode> | ||
<mode>ten.uat</mode> | ||
<mode>ten.dev</mode> | ||
<mode>ten.local</mode> | ||
<mode>ten.sim</mode> | ||
</modes> | ||
</classification> | ||
|
||
<data> | ||
<class name="PySysTest" module="run"/> | ||
</data> | ||
|
||
<traceability> | ||
<requirements> | ||
<requirement id=""/> | ||
</requirements> | ||
</traceability> | ||
</pysystest> |
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,9 @@ | ||
from pysys.basetest import BaseTest | ||
|
||
|
||
class PySysTest(BaseTest): | ||
def execute(self): | ||
pass | ||
|
||
def validate(self): | ||
pass |
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,45 @@ | ||
const fs = require('fs') | ||
const Web3 = require('web3') | ||
const commander = require('commander') | ||
|
||
function log(data) { | ||
let timestamp = new Date().toISOString(); | ||
const entry = `${timestamp} ${data}\n`; | ||
fs.appendFileSync(options.log_file, entry, { flag: 'a' }); | ||
} | ||
|
||
function task(from) { | ||
log('Getting past events from ' + from + ' to latest') | ||
contract.getPastEvents('Guessed', { fromBlock: from, toBlock: 'latest'}).then(function(events) { | ||
if (events.length) { | ||
for (var i = 0, len = events.length; i < len; i+=1) { | ||
log('Guessed event:') | ||
log(' user = ' + events[i].returnValues['user']) | ||
log(' guessedNumber = ' + events[i].returnValues['guessedNumber']) | ||
log(' success = ' + events[i].returnValues['success']) | ||
log(' secretNumber = ' + events[i].returnValues['secretNumber']) | ||
} | ||
} | ||
log('Completed task') | ||
}) | ||
} | ||
|
||
commander | ||
.version('1.0.0', '-v, --version') | ||
.usage('[OPTIONS]...') | ||
.option('--network_ws <value>', 'Web socket connection URL to the network') | ||
.option('--address <value>', 'The contract address') | ||
.option('--contract_abi <value>', 'The contract ABI file') | ||
.option('--log_file <value>', 'The output file to write to') | ||
.option('--from_block <value>', 'Get events from this block to latest') | ||
.parse(process.argv) | ||
|
||
const options = commander.opts() | ||
const web3 = new Web3(`${options.network_ws}`) | ||
|
||
var json = fs.readFileSync(`${options.contract_abi}`) | ||
var abi = JSON.parse(json) | ||
const contract = new web3.eth.Contract(abi, `${options.address}`) | ||
task(options.from_block) | ||
|
||
|
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,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<pysystest type="auto"> | ||
|
||
<description> | ||
<title>Visibility Config: get logs, transparent contract, all events are public</title> | ||
<purpose><![CDATA[ | ||
Uses a simple guessing game, with VisibilityConfig.isTransparent set to true. This opens up calls to get_storage_at, and | ||
additionally makes all events public. Two gateway connections are used, the first by a dev user that deploys the | ||
contract and the second by a player of the game. The dev user waits for the player to play some moves, then runs | ||
a script to getPastEvents on the contract to see what the user was playing. Normally without setting isTransparent to | ||
true, the dev user would not be able to see the events. | ||
]]> | ||
</purpose> | ||
</description> | ||
|
||
<classification> | ||
<groups inherit="true"> | ||
<group>skip</group> | ||
<group>vis_config</group> | ||
</groups> | ||
<modes inherit="true"> | ||
<mode>ten.sepolia</mode> | ||
<mode>ten.uat</mode> | ||
<mode>ten.dev</mode> | ||
<mode>ten.local</mode> | ||
<mode>ten.sim</mode> | ||
<mode>ganache</mode> | ||
</modes> | ||
</classification> | ||
|
||
<data> | ||
<class name="PySysTest" module="run"/> | ||
</data> | ||
|
||
<traceability> | ||
<requirements> | ||
<requirement id=""/> | ||
</requirements> | ||
</traceability> | ||
</pysystest> |
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,40 @@ | ||
import os | ||
from ten.test.basetest import TenNetworkTest | ||
from ten.test.contracts.game import TransparentGuessGame | ||
|
||
|
||
class PySysTest(TenNetworkTest): | ||
|
||
def execute(self): | ||
# connect the dev to the network to deploy the game | ||
network_dev = self.get_network_connection() | ||
web3_dev, account_dev = network_dev.connect_account2(self) | ||
block_number = web3_dev.eth.get_block_number() | ||
game = TransparentGuessGame(self, web3_dev) | ||
game.deploy(network_dev, account_dev) | ||
|
||
# connect a user to the network to play the game and make some guesses | ||
network_usr = self.get_network_connection() | ||
web3_usr, account_usr = network_usr.connect_account1(self) | ||
game_usr = TransparentGuessGame.clone(web3_usr, account_usr, game) | ||
target = game_usr.contract.functions.guess | ||
for i in range(1,5): network_dev.transact(self, web3_usr, target(i), account_usr, game_usr.GAS_LIMIT) | ||
|
||
# run a javascript by the dev to get past events | ||
stdout = os.path.join(self.output, 'poller.out') | ||
stderr = os.path.join(self.output, 'poller.err') | ||
logout = os.path.join(self.output, 'poller.log') | ||
script = os.path.join(self.input, 'poller.js') | ||
args = [] | ||
args.extend(['--network_ws', network_dev.connection_url(web_socket=True)]) | ||
args.extend(['--address', '%s' % game.address]) | ||
args.extend(['--contract_abi', '%s' % game.abi_path]) | ||
args.extend(['--contract_abi', '%s' % game.abi_path]) | ||
args.extend(['--log_file', '%s' % logout]) | ||
args.extend(['--from_block', '%s' % block_number]) | ||
self.run_javascript(script, stdout, stderr, args) | ||
self.waitForGrep(file=logout, expr='Completed task', timeout=30) | ||
|
||
self.assertLineCount(file=logout, expr='Guessed event', condition='==4') | ||
self.assertOrderedGrep(file=logout, exprList=['guessedNumber = %d' % d for d in range(1,5)]) | ||
|
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,45 @@ | ||
const fs = require('fs') | ||
const Web3 = require('web3') | ||
const commander = require('commander') | ||
|
||
function log(data) { | ||
let timestamp = new Date().toISOString(); | ||
const entry = `${timestamp} ${data}\n`; | ||
fs.appendFileSync(options.log_file, entry, { flag: 'a' }); | ||
} | ||
|
||
function task(from) { | ||
log('Getting past events from ' + from + ' to latest') | ||
contract.getPastEvents('Guessed', { fromBlock: from, toBlock: 'latest'}).then(function(events) { | ||
if (events.length) { | ||
for (var i = 0, len = events.length; i < len; i+=1) { | ||
log('Guessed event:') | ||
log(' user = ' + events[i].returnValues['user']) | ||
log(' guessedNumber = ' + events[i].returnValues['guessedNumber']) | ||
log(' success = ' + events[i].returnValues['success']) | ||
log(' secretNumber = ' + events[i].returnValues['secretNumber']) | ||
} | ||
} | ||
log('Completed task') | ||
}) | ||
} | ||
|
||
commander | ||
.version('1.0.0', '-v, --version') | ||
.usage('[OPTIONS]...') | ||
.option('--network_ws <value>', 'Web socket connection URL to the network') | ||
.option('--address <value>', 'The contract address') | ||
.option('--contract_abi <value>', 'The contract ABI file') | ||
.option('--log_file <value>', 'The output file to write to') | ||
.option('--from_block <value>', 'Get events from this block to latest') | ||
.parse(process.argv) | ||
|
||
const options = commander.opts() | ||
const web3 = new Web3(`${options.network_ws}`) | ||
|
||
var json = fs.readFileSync(`${options.contract_abi}`) | ||
var abi = JSON.parse(json) | ||
const contract = new web3.eth.Contract(abi, `${options.address}`) | ||
task(options.from_block) | ||
|
||
|
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,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<pysystest type="auto"> | ||
|
||
<description> | ||
<title>Visibility Config: get logs, public event, one event is public</title> | ||
<purpose><![CDATA[ | ||
Uses a simple guessing game, with VisibilityConfig.eventLogConfigs[0].isPublic set to true. This is set for one event | ||
within the contract, the Guessed event, such that anyone is able to see it. Two gateway connections are used, the | ||
first by a dev user that deploys the contract and the second by a player of the game. The dev user waits for the player | ||
to play some moves, then runs a script to getPastEvents on the contract to see what the user was playing. Normally | ||
without setting isPublic to true, the dev user would not be able to see the event. | ||
]]> | ||
</purpose> | ||
</description> | ||
|
||
<classification> | ||
<groups inherit="true"> | ||
<group>skip</group> | ||
<group>vis_config</group> | ||
</groups> | ||
<modes inherit="true"> | ||
<mode>ten.sepolia</mode> | ||
<mode>ten.uat</mode> | ||
<mode>ten.dev</mode> | ||
<mode>ten.local</mode> | ||
<mode>ten.sim</mode> | ||
</modes> | ||
</classification> | ||
|
||
<data> | ||
<class name="PySysTest" module="run"/> | ||
</data> | ||
|
||
<traceability> | ||
<requirements> | ||
<requirement id=""/> | ||
</requirements> | ||
</traceability> | ||
</pysystest> |
Oops, something went wrong.