From 790c6d2cae5dadc06431b35b6c48993d9b5098e9 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 23 Jan 2020 17:39:15 +0100 Subject: [PATCH] Tests for salted create. --- .../salted_create/salted_create.sol | 23 +++++++++++++++++++ .../salted_create_with_value.sol | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/libsolidity/semanticTests/salted_create/salted_create.sol create mode 100644 test/libsolidity/semanticTests/salted_create/salted_create_with_value.sol diff --git a/test/libsolidity/semanticTests/salted_create/salted_create.sol b/test/libsolidity/semanticTests/salted_create/salted_create.sol new file mode 100644 index 000000000..b20adf74b --- /dev/null +++ b/test/libsolidity/semanticTests/salted_create/salted_create.sol @@ -0,0 +1,23 @@ +contract B +{ +} + +contract A { + function different_salt() public returns (bool) { + B x = new B{salt: "abc"}(); + B y = new B{salt: "abcef"}(); + return x != y; + } + function same_salt() public returns (bool) { + B x = new B{salt: "xyz"}(); + try new B{salt: "xyz"}() {} catch { + return true; + } + return false; + } +} +// ==== +// EVMVersion: >=constantinople +// ---- +// different_salt() -> true +// same_salt() -> true diff --git a/test/libsolidity/semanticTests/salted_create/salted_create_with_value.sol b/test/libsolidity/semanticTests/salted_create/salted_create_with_value.sol new file mode 100644 index 000000000..f8b02693d --- /dev/null +++ b/test/libsolidity/semanticTests/salted_create/salted_create_with_value.sol @@ -0,0 +1,23 @@ +contract B +{ + uint x; + function getBalance() public view returns (uint) { + return address(this).balance * 1000 + x; + } + constructor(uint _x) public payable { + x = _x; + } +} + +contract A { + function f() public payable returns (uint, uint, uint) { + B x = new B{salt: "abc", value: 3}(7); + B y = new B{value: 3}{salt: "abc"}(8); + B z = new B{value: 3, salt: "abc"}(9); + return (x.getBalance(), y.getBalance(), z.getBalance()); + } +} +// ==== +// EVMVersion: >=constantinople +// ---- +// f(), 10 ether -> 3007, 3008, 3009