Skip to content

Commit

Permalink
[diem-transactional-tests] migrate vasps tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vgao1996 authored and bors-libra committed Dec 17, 2021
1 parent af68c84 commit 541bc42
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@
//# b"alice"
//# true
//# -- 0x1::AccountCreationScripts::create_parent_vasp_account

// TODO: is this a duplicate of vasps.move?
46 changes: 46 additions & 0 deletions diem-move/diem-framework/core/transactional-tests/vasps/vasps.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
processed 12 tasks

task 1 'run'. lines 9-17:
Events:
{
key: 00000000000000000000000000000000000000000a550c18
seq_num: 25
type: 0x1::DiemAccount::CreateAccountEvent
data: "6dacafcd926e5bface48cade21c9de2d0500000000000000"
}

task 3 'run'. lines 46-53:
Events:
{
key: 00000000000000000000000000000000000000000a550c18
seq_num: 26
type: 0x1::DiemAccount::CreateAccountEvent
data: "000000000000000000000000000000aa0600000000000000"
}

task 5 'run'. lines 69-76:
Events:
{
key: 00000000000000000000000000000000000000000a550c18
seq_num: 27
type: 0x1::DiemAccount::CreateAccountEvent
data: "000000000000000000000000000000bb0600000000000000"
}

task 8 'run'. lines 106-109:
Events:
{
key: 01000000000000006dacafcd926e5bface48cade21c9de2d
seq_num: 0
type: 0x1::DualAttestation::BaseUrlRotationEvent
data: "000000000000000000"
}
{
key: 00000000000000006dacafcd926e5bface48cade21c9de2d
seq_num: 0
type: 0x1::DualAttestation::ComplianceKeyRotationEvent
data: "203d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c0000000000000000"
}

task 10 'run'. lines 127-193:
Error: Transaction discarded. VMStatus: status ABORTED of type Execution with sub status 519
204 changes: 204 additions & 0 deletions diem-move/diem-framework/core/transactional-tests/vasps/vasps.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
//# init --addresses Parent=0x6dacafcd926e5bface48cade21c9de2d
//# --private-keys Parent=8dd834d205b2e4901e9f9719fbe80b4323127892658d9b269575309179a41f88
//# --validators Vivian

// TODO: is this a duplicate of create_parent_and_child_vasp_accounts.move?

// Create a parent vasp.
//
//# run --signers TreasuryCompliance
//# --type-args 0x1::XUS::XUS
//# --args 0
//# @Parent
//# x"67f819e80aef87be6bbbb30fd671a52f"
//# b"Parent"
//# false
//# --show-events
//# -- 0x1::AccountCreationScripts::create_parent_vasp_account


//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::DiemTimestamp;
use DiemFramework::VASP;
use DiemFramework::DualAttestation;

fun main() {
assert!(VASP::is_vasp(@Parent), 2001);
assert!(VASP::is_parent(@Parent), 2002);
assert!(!VASP::is_child(@Parent), 2003);

assert!(VASP::parent_address(@Parent) == @Parent, 2005);
assert!(DualAttestation::compliance_public_key(@Parent) == x"", 2006);
assert!(DualAttestation::human_name(@Parent) == b"Parent", 2007);
assert!(DualAttestation::base_url(@Parent) == x"", 2008);
assert!(
DualAttestation::expiration_date(@Parent) > DiemTimestamp::now_microseconds(),
2009
);
assert!(VASP::num_children(@Parent) == 0, 2010);
}
}


// Create the first child vasp account with dummy address + dummy auth key prefix.
//
//# run --signers Parent
//# --type-args 0x1::XUS::XUS
//# --args 0xAA
//# x"00000000000000000000000000000000"
//# false
//# 0
//# --show-events
//# -- 0x1::AccountCreationScripts::create_child_vasp_account


//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::VASP;

fun main() {
assert!(VASP::num_children(@Parent) == 1, 2011);
assert!(VASP::parent_address(@0xAA) == @Parent, 2012);
}
}


// Create the second child vasp account with dummy address + dummy auth key prefix.
//
//# run --signers Parent
//# --type-args 0x1::XUS::XUS
//# --args 0xBB
//# x"00000000000000000000000000000000"
//# false
//# 0
//# --show-events
//# -- 0x1::AccountCreationScripts::create_child_vasp_account


//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::VASP;

fun main() {
assert!(VASP::num_children(@Parent) == 2, 2013);
assert!(VASP::parent_address(@0xBB) == @Parent, 2014);
}
}


// TODO: consider splitting the tests into multiple files?

//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::DualAttestation;

fun main() {
let old_pubkey = DualAttestation::compliance_public_key(@Parent);
let new_pubkey = x"3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c";
assert!(old_pubkey != new_pubkey, 2015);
}
}


// Rotate the dual attestation info.
//
//# run --signers Parent
//# --args x"" x"3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c"
//# --show-events
//# -- 0x1::AccountAdministrationScripts::rotate_dual_attestation_info


//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::DualAttestation;

fun main() {
let old_pubkey = DualAttestation::compliance_public_key(@Parent);
let new_pubkey = x"3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c";
assert!(old_pubkey == new_pubkey, 2016);
}
}



// Getting the parent VASP address of a non-VASP should abort.
//
//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::VASP;

fun main() {
VASP::parent_address(@Vivian);
}
}


// TODO: VASP::publish_parent_vasp_credential is now a friend function
// Make into unit test.
// //! new-transaction
// //! sender: blessed
// script {
// use DiemFramework::VASP;
// fun main(account: signer) {
// let account = &account;
// VASP::publish_parent_vasp_credential(account, account);
// abort 99
// }
// }
// // check: "Keep(ABORTED { code: 771,"

// //! new-transaction
// //! sender: diemroot
// script {
// use DiemFramework::VASP;
// fun main(account: signer) {
// let account = &account;
// VASP::publish_parent_vasp_credential(account, account);
// }
// }
// // check: "Keep(ABORTED { code: 258,"

// //! new-transaction
// //! sender: blessed
// script {
// use DiemFramework::VASP;
// fun main(account: signer) {
// let account = &account;
// VASP::publish_child_vasp_credential(account, account);
// }
// }
// // check: "Keep(ABORTED { code: 771,"

// //! new-transaction
// //! sender: blessed
// script {
// use DiemFramework::VASP;
// fun main(account: signer) {
// let account = &account;
// VASP::publish_child_vasp_credential(account, account);
// }
// }
// // check: "Keep(ABORTED { code: 771,"

// //! new-transaction
// //! sender: parent
// script {
// use DiemFramework::VASP;
// fun main(account: signer) {
// let account = &account;
// VASP::publish_child_vasp_credential(account, account);
// }
// }
// // check: "Keep(ABORTED { code: 2307,"


//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::VASP;

fun main() {
assert!(!VASP::is_same_vasp(@Parent, @TreasuryCompliance), 2017);
assert!(!VASP::is_same_vasp(@TreasuryCompliance, @Parent), 2018);
}
}
Loading

0 comments on commit 541bc42

Please sign in to comment.