• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tester.state函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyethereum.tester.state函数的典型用法代码示例。如果您正苦于以下问题:Python state函数的具体用法?Python state怎么用?Python state使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了state函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: consensus

def consensus(reports, reputation, max_iterations=10):
    s = t.state()
    filename = "consensus.se"
    c = s.contract(filename)

    num_voters = len(reputation)
    num_events = len(reports[0])
    v_size = len(reports.flatten())

    reputation_fixed = map(fix, reputation)
    reports_fixed = map(fix, reports.flatten())

    # tx 1: consensus()
    result = s.send(t.k0, c, 0,
                    funid=0,
                    abi=[reports_fixed, reputation_fixed, max_iterations])

    result = np.array(result)
    weighted_centered_data = result[0:v_size]
    votes_filled = result[v_size:(2*v_size)]
    votes_mask = result[(2*v_size):(3*v_size)]

    # pca()
    s = t.state()
    c = s.contract(filename)
    scores = s.send(t.k0, c, 0,
                    funid=1,
                    abi=[weighted_centered_data.tolist(),
                         reputation_fixed,
                         num_voters,
                         num_events,
                         max_iterations])

    # consensus2()
    s = t.state()
    c = s.contract(filename)
    retval = s.send(t.k0, c, 0,
                    funid=2,
                    abi=[reputation_fixed,
                         scores,
                         votes_filled.tolist(),
                         votes_mask.tolist(),
                         num_voters,
                         num_events])

    outcome_final = retval[0:num_events]
    author_bonus = retval[num_events:(2*num_events)]
    voter_bonus = retval[(2*num_events):-2]

    return outcome_final, author_bonus, voter_bonus, retval[-2] - retval[-1]
开发者ID:ChrisCalderon,项目名称:augur-core,代码行数:50,代码来源:optimize.py


示例2: test_callcode

def test_callcode():
    s = tester.state()
    open(filename2, 'w').write(add1_code)
    c = s.contract(callcode_test_code)
    o1 = s.send(tester.k0, c, 0)
    os.remove(filename2)
    assert o1 == [64]
开发者ID:ckeenan,项目名称:pyethereum,代码行数:7,代码来源:test_contracts.py


示例3: test_stateless

def test_stateless():
    s = tester.state()
    open(filename2, "w").write(add1_code)
    c = s.contract(stateless_test_code)
    o1 = s.send(tester.k0, c, 0, [])
    os.remove(filename2)
    assert o1 == [64]
开发者ID:CJentzsch,项目名称:pyethereum,代码行数:7,代码来源:test_contracts.py


示例4: test_crowdfund

def test_crowdfund():
    s = tester.state()
    c = s.abi_contract(crowdfund_code)
    # Create a campaign with id 100
    c.create_campaign(100, 45, 100000, 2)
    # Create a campaign with id 200
    c.create_campaign(200, 48, 100000, 2)
    # Make some contributions
    c.contribute(100, value=1, sender=tester.k1)
    assert [1] == c.progress_report(100)
    c.contribute(200, value=30000, sender=tester.k2)
    c.contribute(100, value=59049, sender=tester.k3)
    assert [59050] == c.progress_report(100)
    c.contribute(200, value=70001, sender=tester.k4)
    # Expect the 100001 units to be delivered to the destination
    # account for campaign 2
    assert 100001 == s.block.get_balance(utils.int_to_addr(48))
    mida1 = s.block.get_balance(tester.a1)
    mida3 = s.block.get_balance(tester.a3)
    # Mine 5 blocks to expire the campaign
    s.mine(5)
    # Ping the campaign after expiry
    c.contribute(100, value=1)
    # Expect refunds
    assert mida1 + 1 == s.block.get_balance(tester.a1)
    assert mida3 + 59049 == s.block.get_balance(tester.a3)
开发者ID:ckeenan,项目名称:pyethereum,代码行数:26,代码来源:test_contracts.py


示例5: test_sort

def test_sort():
    s = tester.state()
    c = s.abi_contract(sort_code)
    assert c.sort([9]) == [9]
    assert c.sort([9, 5]) == [5, 9]
    assert c.sort([9, 3, 5]) == [3, 5, 9]
    assert c.sort([80, 234, 112, 112, 29]) == [29, 80, 112, 112, 234]
开发者ID:ckeenan,项目名称:pyethereum,代码行数:7,代码来源:test_contracts.py


示例6: test_returnten

def test_returnten():
    s = tester.state()
    open(filename, 'w').write(mul2_code)
    c = s.contract(returnten_code)
    o1 = s.send(tester.k0, c, 0)
    os.remove(filename)
    assert o1 == [10]
开发者ID:ckeenan,项目名称:pyethereum,代码行数:7,代码来源:test_contracts.py


示例7: compile

def compile(filename):
    s = t.state()
    start = time.time()
    printf('Compiling...\t')
    c = suppress_output(lambda: s.abi_contract(filename))
    printf('Done in %.1f seconds.\n', time.time() - start)
    return c
开发者ID:ChrisCalderon,项目名称:augur-core,代码行数:7,代码来源:test_suite.py


示例8: test_reverter

def test_reverter():
    s = tester.state()
    c = s.contract(reverter_code, endowment=10 ** 15)
    s.send(tester.k0, c, 0, [0])
    assert s.block.get_storage_data(c, 8080) == 4040
    assert s.block.get_balance("0" * 39 + "1") == 9
    assert s.block.get_storage_data(c, 8081) == 0
    assert s.block.get_balance("0" * 39 + "2") == 0
开发者ID:CJentzsch,项目名称:pyethereum,代码行数:8,代码来源:test_contracts.py


示例9: setup_method

    def setup_method(self, method):
        self.state = tester.state()

        self.namereg_contract = self.state.contract(self.namereg)

        self.contract = self.state.contract(self.etherex)
        self.etx_contract = self.state.contract(self.etx)
        self.bob_contract = self.state.contract(self.bob)
开发者ID:QUASI-DEV,项目名称:etherex,代码行数:8,代码来源:etherex.py


示例10: test_reverter

def test_reverter():
    s = tester.state()
    c = s.abi_contract(reverter_code, endowment=10**15)
    c.entry()
    assert s.block.get_storage_data(c.address, 8080) == 4040
    assert s.block.get_balance('0'*39+'7') == 9
    assert s.block.get_storage_data(c.address, 8081) == 0
    assert s.block.get_balance('0'*39+'8') == 0
开发者ID:ckeenan,项目名称:pyethereum,代码行数:8,代码来源:test_contracts.py


示例11: test_storagevar_fails

def test_storagevar_fails():
    s = tester.state()
    success1, success2, success3, success4, success5, success6 = \
        0, 0, 0, 0, 0, 0
    try:
        s.contract(fail1)
    except Exception, e:
        success1 = "Storage variable access not deep enough" in str(e)
开发者ID:ckeenan,项目名称:pyethereum,代码行数:8,代码来源:test_contracts.py


示例12: test_blockhashes_300

def test_blockhashes_300():
    s = tester.state()
    s.mine(300)
    o = s.block.get_ancestor_list(256)
    assert o[0] == s.block == s.blocks[300]
    for i in range(1, 257):
        assert o[i] == s.blocks[300-i]
    assert len(o) == 257
开发者ID:ckeenan,项目名称:pyethereum,代码行数:8,代码来源:test_blockhashes.py


示例13: run_serpent

def run_serpent(contract, parms, convert_to_int=False):
    """Call a serpent (.se) contract on a test blockchain"""
    if convert_to_int:
        args = convert_args(parms)
    else:
        args = parms
    s = t.state()  #Initialize a genesis block
    c = s.contract(contract)
    return s.send(t.k0, c, 0, [args])
开发者ID:SimonJester,项目名称:playground,代码行数:9,代码来源:runserpent.py


示例14: test_post

def test_post():
    s = tester.state()
    c = s.contract(arither_code)
    s.send(tester.k0, c, 0, [1])
    o2 = s.send(tester.k0, c, 0, [3])
    assert o2 == [1010]
    c = s.contract(arither_code)
    s.send(tester.k0, c, 0, [2])
    o2 = s.send(tester.k0, c, 0, [3])
    assert o2 == [1001]
开发者ID:CJentzsch,项目名称:pyethereum,代码行数:10,代码来源:test_contracts.py


示例15: test_saveload

def test_saveload():
    s = tester.state()
    c = s.abi_contract(saveload_code)
    o = c.kall()
    assert o[0] == 0x73697220626f62616c6f7420746f207468652072657363756520212131213121, bitcoin.encode(o[0], 16)
    assert o[1] == 0x2131213100000000000000000000000000000000000000000000000000000000, bitcoin.encode(o[1], 16)
    assert o[2] == 0x73697220626f62616c6f7420746f207468652072657363756520212131213121, bitcoin.encode(o[2], 16)
    assert o[3] == 0x2131213100000000000000000000000000000000000000000000000000000000, bitcoin.encode(o[3], 16)
    assert o[4] == 0x73697220626f62616c6f7420746f207468652072657363756520212131213121, bitcoin.encode(o[4], 16)
    assert o[5] == 0x2100000000000000000000000000000000000000000000000000000000000000, bitcoin.encode(o[5], 16)
开发者ID:ckeenan,项目名称:pyethereum,代码行数:10,代码来源:test_contracts.py


示例16: test_calls

def test_calls():
    s = tester.state()
    c = s.abi_contract(calltest_code)
    c.main()
    assert [12345] == c.get(1)
    assert [23456] == c.get(2)
    assert [34567] == c.get(3)
    c.first(4, 5, 6, 7, 8)
    assert [45678] == c.get(1)
    c.second(5, 6, 7, 8, 9)
    assert [56789] == c.get(2)
开发者ID:ckeenan,项目名称:pyethereum,代码行数:11,代码来源:test_contracts.py


示例17: test_currency

def test_currency():
    s = tester.state()
    c = s.abi_contract(currency_code, sender=tester.k0)
    o1 = c.send(tester.a2, 200)
    assert o1 == [1]
    o2 = c.send(tester.a2, 900)
    assert o2 == [0]
    o3 = c.query(tester.a0)
    assert o3 == [800]
    o4 = c.query(tester.a2)
    assert o4 == [200]
开发者ID:ckeenan,项目名称:pyethereum,代码行数:11,代码来源:test_contracts.py


示例18: setup_method

    def setup_method(self, method):
        self.state = tester.state()

        self.ncontract = self.state.contract(self.ncode)

        self.contract = self.state.contract(self.code)
        self.bcontract = self.state.contract(self.bcode)
        self.icontract = self.state.contract(self.icode)
        self.tcontract = self.state.contract(self.tcode)
        self.ccontract = self.state.contract(self.ccode)
        self.xcontract = self.state.contract(self.xcode)
开发者ID:halpeople,项目名称:etherex,代码行数:11,代码来源:etherex.py


示例19: test_sha256

def test_sha256():
    s = tester.state()
    c = s.contract(sha256_code)
    assert s.send(tester.k0, c, 0) == [
        0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - 2**256,
        0xd9147961436944f43cd99d28b2bbddbf452ef872b30c8279e255e7daafc7f946 - 2**256,
        0xcd6357efdd966de8c0cb2f876cc89ec74ce35f0968e11743987084bd42fb8944 - 2**256,
        0xcd6357efdd966de8c0cb2f876cc89ec74ce35f0968e11743987084bd42fb8944 - 2**256,
        0xb393978842a0fa3d3e1470196f098f473f9678e72463cb65ec4ab5581856c2e4 - 2**256,
        0xb393978842a0fa3d3e1470196f098f473f9678e72463cb65ec4ab5581856c2e4 - 2**256
    ]
开发者ID:ckeenan,项目名称:pyethereum,代码行数:11,代码来源:test_contracts.py


示例20: test_blockhashes_10

def test_blockhashes_10():
    s = tester.state()
    s.mine(10)
    o = s.block.get_ancestor_list(256)
    print o
    assert o[0] == s.block == s.blocks[10]
    for i in range(1, 10):
        assert o[i] == s.blocks[10-i]
    for i in range(11, 257):
        assert o[i] is None
    assert len(o) == 257
开发者ID:ckeenan,项目名称:pyethereum,代码行数:11,代码来源:test_blockhashes.py



注:本文中的pyethereum.tester.state函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.sha3函数代码示例发布时间:2022-05-25
下一篇:
Python blocks.genesis函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap