Skip to content

Commit

Permalink
Visibility config part 4 (#347)
Browse files Browse the repository at this point in the history
* Use single gateway

* Addition of placeholders

* Completed first getPastEvents test

* Addition

* Placeholders

* Addition

* Addition
  • Loading branch information
moraygrieve authored Sep 26, 2024
1 parent d5af8f6 commit 119478a
Show file tree
Hide file tree
Showing 23 changed files with 531 additions and 20 deletions.
5 changes: 3 additions & 2 deletions tests/generic/gen_cor_071/pysystest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
<purpose><![CDATA[
This is all implemented in the process of the test, where after performing transactions on a contract a filter is placed
on the contract and all new entries are queried for.
Skipped due to https://github.com/ten-protocol/ten-internal/issues/1461
]]>
</purpose>
</description>

<skipped reason="https://github.com/ten-protocol/ten-internal/issues/1461"/>

<classification>
<groups inherit="true">
<group>skip</group>
<group>events</group>
</groups>
<modes inherit="true">
Expand Down
5 changes: 3 additions & 2 deletions tests/generic/gen_cor_072/pysystest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
This is a polling implementation in python to get event logs from a contract as transactions are written to it in real
time. It creates a filter on the events.Event method on the contract instance, then repeatedly calls for
get_new_entries() on the filter to return new logs. As a polling implementation it uses HTTP for the connection protocol.
Skipped due to https://github.com/ten-protocol/ten-internal/issues/1461
]]>
</purpose>
</description>

<skipped reason="https://github.com/ten-protocol/ten-internal/issues/1461"/>

<classification>
<groups inherit="true">
<group>skip</group>
<group>events</group>
</groups>
<modes inherit="true">
Expand Down
7 changes: 4 additions & 3 deletions tests/ten/ten_cor_060/pysystest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
<description>
<title>Visibility Config: subscribe, transparent contract, call storageAt</title>
<purpose><![CDATA[
Use a simple guessing game, with VisibilityConfig.isTransparent set to true. This opens up calls to get_storage_at, and
additionally makes all event public. In this test only calls to get_storage_at are used to try and figure out the
secret number to guess, and to win the game in a single call.
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 player of the games attempts to use get_storage_at to try and
figure out the secret number to guess, and to win the game in a single call.
Skipped due to https://github.com/ten-protocol/ten-internal/issues/3933
]]>
Expand Down
2 changes: 1 addition & 1 deletion tests/ten/ten_cor_061/pysystest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Visibility Config: subscribe, transparent contract, all events are public</title>
<purpose><![CDATA[
Use a simple guessing game, with VisibilityConfig.isTransparent set to true. This opens up calls to get_storage_at, and
additionally makes all events public. In this test two gateways are used, the first by a dev user that deploys the
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 has a subscriber to the events, and should be able to
see the events even though they contain an EOA which does not belong to them.
Expand Down
10 changes: 5 additions & 5 deletions tests/ten/ten_cor_061/run.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from ten.test.basetest import TenNetworkTest
from ten.test.contracts.game import TransparentGuessGameOneFile
from ten.test.contracts.game import TransparentGuessGame
from ten.test.helpers.log_subscriber import AllEventsLogSubscriber


class PySysTest(TenNetworkTest):

def execute(self):
# connect to the network and deploy the game
network_dev = self.get_network_connection(name='dev')
network_dev = self.get_network_connection()
web3_dev, account_dev = network_dev.connect_account2(self)
game = TransparentGuessGameOneFile(self, web3_dev)
game = TransparentGuessGame(self, web3_dev)
game.deploy(network_dev, account_dev)

# connect a user to the network
network_usr = self.get_network_connection(name='user')
network_usr = self.get_network_connection()
web3_usr, account_usr = network_usr.connect_account1(self)
game_usr = TransparentGuessGameOneFile.clone(web3_usr, account_usr, game)
game_usr = TransparentGuessGame.clone(web3_usr, account_usr, game)

# run a background script to filter and collect events
subscriber = AllEventsLogSubscriber(self, network_dev, game.address, game.abi_path)
Expand Down
9 changes: 4 additions & 5 deletions tests/ten/ten_cor_062/pysystest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
<description>
<title>Visibility Config: subscribe, public event, one event is public</title>
<purpose><![CDATA[
Use 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 receive call backs for it. In this test two gateways
are used, the first by a dev user that deploys the contract and the second by a player of the game. The dev user has a
subscriber to the events, and should be able to see the events even though they contain an EOA which does not belong
to them.
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 has a subscriber to the
events, and should be able to see the events even though they contain an EOA which does not belong to them.
Skipped due to https://github.com/ten-protocol/ten-internal/issues/3933 (may be related)
]]>
Expand Down
4 changes: 2 additions & 2 deletions tests/ten/ten_cor_062/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class PySysTest(TenNetworkTest):

def execute(self):
# connect to the network and deploy the game
network_dev = self.get_network_connection(name='dev')
network_dev = self.get_network_connection()
web3_dev, account_dev = network_dev.connect_account2(self)
game = PublicEventGuessGame(self, web3_dev)
game.deploy(network_dev, account_dev)

# connect a user to the network
network_usr = self.get_network_connection(name='user')
network_usr = self.get_network_connection()
web3_usr, account_usr = network_usr.connect_account1(self)
game_usr = PublicEventGuessGame.clone(web3_usr, account_usr, game)

Expand Down
34 changes: 34 additions & 0 deletions tests/ten/ten_cor_063/pysystest.xml
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>
9 changes: 9 additions & 0 deletions tests/ten/ten_cor_063/run.py
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
45 changes: 45 additions & 0 deletions tests/ten/ten_cor_065/Input/poller.js
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)


40 changes: 40 additions & 0 deletions tests/ten/ten_cor_065/pysystest.xml
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>
40 changes: 40 additions & 0 deletions tests/ten/ten_cor_065/run.py
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)])

45 changes: 45 additions & 0 deletions tests/ten/ten_cor_066/Input/poller.js
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)


39 changes: 39 additions & 0 deletions tests/ten/ten_cor_066/pysystest.xml
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>
Loading

0 comments on commit 119478a

Please sign in to comment.