This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7111 from taokayan/get-sender-kayan
Implement GET_SENDER protocol feature
- Loading branch information
Showing
18 changed files
with
246 additions
and
8 deletions.
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
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
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
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,6 @@ | ||
if( EOSIO_COMPILE_TEST_CONTRACTS ) | ||
add_contract( get_sender_test get_sender_test get_sender_test.cpp ) | ||
else() | ||
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/get_sender_test.wasm ${CMAKE_CURRENT_BINARY_DIR}/get_sender_test.wasm COPYONLY ) | ||
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/get_sender_test.abi ${CMAKE_CURRENT_BINARY_DIR}/get_sender_test.abi COPYONLY ) | ||
endif() |
69 changes: 69 additions & 0 deletions
69
unittests/test-contracts/get_sender_test/get_sender_test.abi
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,69 @@ | ||
{ | ||
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", | ||
"version": "eosio::abi/1.1", | ||
"types": [], | ||
"structs": [ | ||
{ | ||
"name": "assertsender", | ||
"base": "", | ||
"fields": [ | ||
{ | ||
"name": "expected_sender", | ||
"type": "name" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "notify", | ||
"base": "", | ||
"fields": [ | ||
{ | ||
"name": "to", | ||
"type": "name" | ||
}, | ||
{ | ||
"name": "expected_sender", | ||
"type": "name" | ||
}, | ||
{ | ||
"name": "send_inline", | ||
"type": "bool" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "sendinline", | ||
"base": "", | ||
"fields": [ | ||
{ | ||
"name": "to", | ||
"type": "name" | ||
}, | ||
{ | ||
"name": "expected_sender", | ||
"type": "name" | ||
} | ||
] | ||
} | ||
], | ||
"actions": [ | ||
{ | ||
"name": "assertsender", | ||
"type": "assertsender", | ||
"ricardian_contract": "" | ||
}, | ||
{ | ||
"name": "notify", | ||
"type": "notify", | ||
"ricardian_contract": "" | ||
}, | ||
{ | ||
"name": "sendinline", | ||
"type": "sendinline", | ||
"ricardian_contract": "" | ||
} | ||
], | ||
"tables": [], | ||
"ricardian_clauses": [], | ||
"variants": [] | ||
} |
30 changes: 30 additions & 0 deletions
30
unittests/test-contracts/get_sender_test/get_sender_test.cpp
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,30 @@ | ||
/** | ||
* @file | ||
* @copyright defined in eos/LICENSE | ||
*/ | ||
#include "get_sender_test.hpp" | ||
#include <eosio/transaction.hpp> | ||
|
||
using namespace eosio; | ||
|
||
void get_sender_test::assertsender( name expected_sender ) { | ||
check( get_sender() == expected_sender, "sender did not match" ); | ||
} | ||
|
||
void get_sender_test::sendinline( name to, name expected_sender ) { | ||
assertsender_action a( to, std::vector<eosio::permission_level>{} ); | ||
a.send( expected_sender ); | ||
} | ||
|
||
void get_sender_test::notify( name to, name expected_sender, bool send_inline ) { | ||
require_recipient( to ); | ||
} | ||
|
||
void get_sender_test::on_notify( name to, name expected_sender, bool send_inline ) { | ||
if( send_inline ) { | ||
assertsender_action a( get_first_receiver(), std::vector<eosio::permission_level>{} ); | ||
a.send( expected_sender ); | ||
} else { | ||
check( get_sender() == expected_sender, "sender did not match" ); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
unittests/test-contracts/get_sender_test/get_sender_test.hpp
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,43 @@ | ||
/** | ||
* @file | ||
* @copyright defined in eos/LICENSE | ||
*/ | ||
#pragma once | ||
|
||
#include <eosio/eosio.hpp> | ||
|
||
namespace eosio { | ||
namespace internal_use_do_not_use { | ||
extern "C" { | ||
__attribute__((eosio_wasm_import)) | ||
uint64_t get_sender(); | ||
} | ||
} | ||
} | ||
|
||
namespace eosio { | ||
name get_sender() { | ||
return name( internal_use_do_not_use::get_sender() ); | ||
} | ||
} | ||
|
||
class [[eosio::contract]] get_sender_test : public eosio::contract { | ||
public: | ||
using eosio::contract::contract; | ||
|
||
[[eosio::action]] | ||
void assertsender( eosio::name expected_sender ); | ||
using assertsender_action = eosio::action_wrapper<"assertsender"_n, &get_sender_test::assertsender>; | ||
|
||
[[eosio::action]] | ||
void sendinline( eosio::name to, eosio::name expected_sender ); | ||
|
||
[[eosio::action]] | ||
void notify( eosio::name to, eosio::name expected_sender, bool send_inline ); | ||
|
||
// eosio.cdt 1.6.1 has a problem with "*::notify" so hardcode to tester1 for now. | ||
// TODO: Change it back to "*::notify" when the bug is fixed in eosio.cdt. | ||
[[eosio::on_notify("tester1::notify")]] | ||
void on_notify( eosio::name to, eosio::name expected_sender, bool send_inline ); | ||
|
||
}; |
Binary file not shown.
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
Binary file not shown.