This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add function to create Filecoin Address from ActorID (#317)
* feat: add function to create Filecoin Address from ActorID * added a test * typo
- Loading branch information
Showing
6 changed files
with
192 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/******************************************************************************* | ||
* (c) 2023 Zondax AG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
********************************************************************************/ | ||
// | ||
// DRAFT!! THIS CODE HAS NOT BEEN AUDITED - USE ONLY FOR PROTOTYPING | ||
|
||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.17; | ||
|
||
import "../utils/Leb128.sol"; | ||
import "../utils/FilAddresses.sol"; | ||
import "../types/CommonTypes.sol"; | ||
import "../external/Buffer.sol"; | ||
|
||
/// @notice This file is meant to serve as a deployable contract of the Address lib, as the library by itself is not. | ||
/// @notice It imports the library and create a callable method for each method in the library | ||
/// @author Zondax AG | ||
contract AddressTest { | ||
|
||
function actorid_conversion() public pure { | ||
uint64 actorID = 1; | ||
CommonTypes.FilAddress memory result = FilAddresses.fromActorID(actorID); | ||
|
||
require(keccak256(result.data) == keccak256(hex"0001"), "'1' actorID is not returning '0001'"); | ||
} | ||
|
||
|
||
} |
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,77 @@ | ||
use fil_actor_eam::Return; | ||
use fil_actor_evm::Method as EvmMethods; | ||
use fil_actors_runtime::EAM_ACTOR_ADDR; | ||
use fvm::executor::{ApplyKind, Executor}; | ||
use fvm_integration_tests::dummy::DummyExterns; | ||
use fvm_integration_tests::tester::Account; | ||
use fvm_ipld_encoding::strict_bytes; | ||
use fvm_ipld_encoding::RawBytes; | ||
use fvm_shared::address::Address; | ||
use fvm_shared::message::Message; | ||
use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize}; | ||
|
||
use testing::setup; | ||
|
||
const WASM_COMPILED_PATH: &str = "../build/v0.8/tests/AddressTest.bin"; | ||
|
||
#[derive(SerdeSerialize, SerdeDeserialize)] | ||
#[serde(transparent)] | ||
pub struct CreateExternalParams(#[serde(with = "strict_bytes")] pub Vec<u8>); | ||
|
||
#[test] | ||
fn address_tests() { | ||
println!("Testing Address lib"); | ||
|
||
let (mut tester, _manifest) = setup::setup_tester(); | ||
|
||
let sender: [Account; 1] = tester.create_accounts().unwrap(); | ||
|
||
// Instantiate machine | ||
tester.instantiate_machine(DummyExterns).unwrap(); | ||
|
||
let executor = tester.executor.as_mut().unwrap(); | ||
|
||
println!("Calling init actor (EVM)"); | ||
|
||
let evm_bin = setup::load_evm(WASM_COMPILED_PATH); | ||
|
||
let constructor_params = CreateExternalParams(evm_bin); | ||
|
||
let message = Message { | ||
from: sender[0].1, | ||
to: EAM_ACTOR_ADDR, | ||
gas_limit: 1000000000, | ||
method_num: 4, | ||
sequence: 0, | ||
params: RawBytes::serialize(constructor_params).unwrap(), | ||
..Message::default() | ||
}; | ||
|
||
let res = executor | ||
.execute_message(message, ApplyKind::Explicit, 100) | ||
.unwrap(); | ||
|
||
assert_eq!(res.msg_receipt.exit_code.value(), 0); | ||
|
||
let exec_return: Return = RawBytes::deserialize(&res.msg_receipt.return_data).unwrap(); | ||
|
||
let contract_actor_id = exec_return.actor_id; | ||
|
||
println!("Calling `fromActorID`"); | ||
|
||
let message = Message { | ||
from: sender[0].1, | ||
to: Address::new_id(contract_actor_id), | ||
gas_limit: 1000000000, | ||
method_num: EvmMethods::InvokeContract as u64, | ||
sequence: 1, | ||
params: RawBytes::new(hex::decode("44a0a86647").unwrap()), | ||
..Message::default() | ||
}; | ||
|
||
let res = executor | ||
.execute_message(message, ApplyKind::Explicit, 100) | ||
.unwrap(); | ||
|
||
assert_eq!(res.msg_receipt.exit_code.value(), 0); | ||
} |