Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mpm] add some integration test #3635

Merged
merged 1 commit into from
Aug 10, 2022
Merged

[mpm] add some integration test #3635

merged 1 commit into from
Aug 10, 2022

Conversation

jolestar
Copy link
Member

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

test

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Other information

@jolestar jolestar merged commit b6aa4f3 into master Aug 10, 2022
@jolestar jolestar deleted the mpm_integration_test branch August 10, 2022 14:05
@baichuan3
Copy link

baichuan3 commented Aug 11, 2022

DAO Proposal集成测试时遇到了一些问题,call-api state.get_with_proof_by_root_raw 有两个参数 [access_path, state_root],有两个问题:
1)state_root依赖前一个接口chain.info的返回,貌似call-api里还不支持$.call-api结果解析,如下:
//# call-api state.get_with_proof_by_root_raw [xxx, {{$.call-api[0].head.state_root}}]
会报错MiscellaneousError

2)另一个参数access_path也不是固定的,已经实现了Move合约里依据DAO动态生成access_path的逻辑,但move生成的如何传参给call-api又是个问题。

整体的测试代码放到下面了:

//# init -n dev

//# faucet --addr creator --amount 100000000000

//# call-api chain.info

//# call-api state.get_with_proof_by_root_raw ["0x6bfb460477adf9dd0455d3de2fc7f211/1/0x00000000000000000000000000000001::IdentifierNFT::IdentifierNFT<0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::DaoMember<0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::SbtTestDAO>,0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::DaoMemberBody<0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::SbtTestDAO>>",{{$.call-api[0].head.state_root}}]

@jolestar
Copy link
Member Author

后面的参数少了引号。可以在 init 中加入 --debug 参数,就可以看输出结果。

//# init -n dev --debug

//# faucet --addr creator --amount 100000000000

//# call-api chain.info

//# call-api state.get_with_proof_by_root_raw ["0x6bfb460477adf9dd0455d3de2fc7f211/1/0x00000000000000000000000000000001::IdentifierNFT::IdentifierNFT<0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::DaoMember<0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::SbtTestDAO>,0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::DaoMemberBody<0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::SbtTestDAO>>","{{$.call-api[0].head.state_root}}"]

@jolestar
Copy link
Member Author

另一个参数access_path也不是固定的,已经实现了Move合约里依据DAO动态生成access_path的逻辑,但move生成的如何传参给call-api又是个问题。

这个感觉需要在命令行里拼接出来。你在 Move 里是怎么拼的?

@baichuan3
Copy link

后面的参数少了引号。可以在 init 中加入 --debug 参数,就可以看输出结果。

//# init -n dev --debug

//# faucet --addr creator --amount 100000000000

//# call-api chain.info

//# call-api state.get_with_proof_by_root_raw ["0x6bfb460477adf9dd0455d3de2fc7f211/1/0x00000000000000000000000000000001::IdentifierNFT::IdentifierNFT<0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::DaoMember<0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::SbtTestDAO>,0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::DaoMemberBody<0x6bfb460477adf9dd0455d3de2fc7f211::SBTModule::SbtTestDAO>>","{{$.call-api[0].head.state_root}}"]

继续回来测试这块了。这段执行后打印的日志里没有第二条call-api日志,加了个方法打印第二个call-api的结果,也报错了。
感觉这个地方还是有个bug。
测试例子:https://github.com/starcoinorg/starcoin-framework/blob/dao_integration_test/integration-tests/daospace/test-call-api.move

mpm integration-test test-call-api.move
BUILDING StarcoinFramework

running 1 tests
Hack account 0x0000000000000000000000000a550c18
Hack account 0x662ba5a1a1da0f1c70a9762c7eeb7aaf
Hack account 0x6bfb460477adf9dd0455d3de2fc7f211
call-api: {"block_info":{"block_accumulator_info":{"accumulator_root":"0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000","frozen_subtree_roots":[],"num_leaves":"0","num_nodes":"0"},"block_hash":"0x162c92ef95c744121430ab2de7c1b2227329e7483cce06130aee41dda6c99444","total_difficulty":"0x00","txn_accumulator_info":{"accumulator_root":"0x0f874ee69968f651ac77a7f048f5aa80d44b561075de9d519d6aa141885ab49a","frozen_subtree_roots":["0x0f874ee69968f651ac77a7f048f5aa80d44b561075de9d519d6aa141885ab49a"],"num_leaves":"1","num_nodes":"1"}},"chain_id":254,"genesis_hash":"0x6500e4872dc02b20b3b95369c3642a75c16504be324409524fc97c9fa31d86a4","head":{"author":"0x00000000000000000000000000000001","author_auth_key":null,"block_accumulator_root":"0xc802c453412f78386b1f87d1b4b3fdd1540704f11f8fc835de932589262cea8d","block_hash":"0x162c92ef95c744121430ab2de7c1b2227329e7483cce06130aee41dda6c99444","body_hash":"0xc01e0329de6d899348a8ef4bd51db56175b3fa0988e57c3dcec8eaf13a164d97","chain_id":254,"difficulty":"0x00","extra":"0x00000000","gas_used":"0","nonce":0,"number":"1","parent_hash":"0xb695baa2a60486347d95e9436888ffdc6ed39ac9caa0f2a4f6194f964640aed9","state_root":"0x8851def508098ae4ed9834a701d623acea61cbcf67272735f6c3977e68958015","timestamp":"10000","txn_accumulator_root":"0x0f874ee69968f651ac77a7f048f5aa80d44b561075de9d519d6aa141885ab49a"}}
test integration-test::daospace/test-call-api.move ... ok

test result: ok. 1 passed; 0 failed; 143 filtered out

@jolestar
Copy link
Member Author

@baichuan3 第二个 api 调用出错了,出错现在不会打印 debug 信息,可以先生成 exp 文件,出错信息会和 exp 比较,就会打印出来。出错的问题在 #3664 修复了。

@baichuan3
Copy link

@baichuan3 第二个 api 调用出错了,出错现在不会打印 debug 信息,可以先生成 exp 文件,出错信息会和 exp 比较,就会打印出来。出错的问题在 #3664 修复了。

验证ok了

@baichuan3
Copy link

另一个参数access_path也不是固定的,已经实现了Move合约里依据DAO动态生成access_path的逻辑,但move生成的如何传参给call-api又是个问题。

这个感觉需要在命令行里拼接出来。你在 Move 里是怎么拼的?

Move里实现了一个方法,传入DAOT类型和用户的address,返回对应的access_path,原始方法签名:
public fun get_access_path<DaoT: store>(user_addr: address): vector {}

看mpm fork版本里,除了支持call-api外,还支持call调用.

能否通过call或者其它命令,调用以下方法,然后在call-api使用其返回值?
0x1::SnapshotUtil::get_access_path --args user_address

如果上述方式可行,会比较优雅。

同时尝试了另外一种相对tricky的思路,在faucet里执行address,遇到的问题是,指定address后不能使用alias别名,例如执行creator的地址,该思路可以预先拼好access path,但不够灵活。

@jolestar @0xpause

@jolestar
Copy link
Member Author

可以的,任何命令的输出都可以作为后面命令的输入

@pause125
Copy link
Collaborator

可以的,任何命令的输出都可以作为后面命令的输入

这个 feature 是已经实现了吗?

@baichuan3
Copy link

最后一个卡点,解决了整个DAO的集成测试就能跑通了。 @jolestar @0xpause

写了个简单的直接call的例子,能跑通:

//# init -n dev

//# faucet --addr creator --amount 100000000000

//# block --author=0x2

//# call 0x1::Block::get_current_block_number

//# run --signers creator --args {{$.call[0]}}u64
script{
    use StarcoinFramework::Debug;
    fun main(_sender: signer, block_number: u64){
        Debug::print(&block_number);
    }
}

不过上述的场景,遇到两个问题:
1)接口里有泛型DAOT,测试用例里的泛型实例为0x6bfb460477adf9dd0455d3de2fc7f211::DAOHelper::X,这个泛型应该怎么传?
2)call里的参数address来自faucet creator,在call里怎么传参creator?

//# faucet --addr creator --amount 100000000000

//# block --author=0x2

//# call 0x1::SnapshotUtil::get_access_path -t [todo] --args [@creator]

//# run --signers creator --args {{$.call[0]}}
script{
    use StarcoinFramework::Debug;
    fun main(_sender: signer, access_path: vector<u8>){
        Debug::print(&access_path);
    }
}

@jolestar
Copy link
Member Author

可以的,任何命令的输出都可以作为后面命令的输入

这个 feature 是已经实现了吗?

对,实现了。

@pause125
Copy link
Collaborator

最后一个卡点,解决了整个DAO的集成测试就能跑通了。 @jolestar @0xpause

写了个简单的直接call的例子,能跑通:

//# init -n dev

//# faucet --addr creator --amount 100000000000

//# block --author=0x2

//# call 0x1::Block::get_current_block_number

//# run --signers creator --args {{$.call[0]}}u64
script{
    use StarcoinFramework::Debug;
    fun main(_sender: signer, block_number: u64){
        Debug::print(&block_number);
    }
}

不过上述的场景,遇到两个问题: 1)接口里有泛型DAOT,测试用例里的泛型实例为0x6bfb460477adf9dd0455d3de2fc7f211::DAOHelper::X,这个泛型应该怎么传? 2)call里的参数address来自faucet creator,在call里怎么传参creator?

//# faucet --addr creator --amount 100000000000

//# block --author=0x2

//# call 0x1::SnapshotUtil::get_access_path -t [todo] --args [@creator]

//# run --signers creator --args {{$.call[0]}}
script{
    use StarcoinFramework::Debug;
    fun main(_sender: signer, access_path: vector<u8>){
        Debug::print(&access_path);
    }
}

1)泛型参数可以通过 -t / --type-args 指定
2)address 使用 "@Creator" 的写法目前好像不行,我看看能不能修改。不过目前有一个替代办法: faucet creator 的地址不是随机的,是固定的,可以暂时把地址打印出来,然后硬编码。

一个通过的 case:

//# init -n dev --debug

//# faucet --addr creator --amount 100000000000

//# call 0x1::Account::balance --type-args 0x1::STC::STC --args 0x662ba5a1a1da0f1c70a9762c7eeb7aaf

//# run --signers creator --args {{$.call[0]}}u128

script{
     use StarcoinFramework::Debug;
     fun main(_sender: signer, balance: u128) {
        Debug::print<address>(&@creator);
        Debug::print(&balance);
     }
}

@jolestar
Copy link
Member Author

@baichuan3 @0xpause

faucet 的 Json Output 现在是 None,感觉应该返回那个 TransactionWithOutput, 这样就能拿到 faucet 交易的信息。

match output.output.status {
TransactionStatusView::Executed => {
self.hack_account(addr)?;
Ok((None, None))
}
_ => {
bail!(
"Failed to faucet {}, status: {:?}",
addr,
output.output.status
);
}
}

另外一个 workaround 的办法是部署一个 module 然后提供一个方法返回 creator 的地址,然后在后面的命令里 call

@pause125
Copy link
Collaborator

返回 faucet 的交易信息这个方式也符合 mpm 现在的模式,我按这个思路改一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants