This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PAN-2343] smart contract permission controller (#1083)
* [PAN-2343] some stubs in progress * [PAN-2343] getting close to what could be a working contract controller * [PAN-2343] added the permissioning provider interface to the smart contract controller * [PAN-2343] smart permissioning queryer works * [PAN-2343] docs for the smart contract permissioning controller * [PAN-2343] removed some bad debugging * [PAN-2343] docs * [PAN-2343] final * [PAN-2343] charsets * [PAN-2343] dependencies that are missing
- Loading branch information
1 parent
1d5ac74
commit 3033c18
Showing
5 changed files
with
358 additions
and
2 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
152 changes: 152 additions & 0 deletions
152
...ech/pegasys/pantheon/ethereum/permissioning/SmartContractPermissioningControllerTest.java
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,152 @@ | ||
/* | ||
* Copyright 2019 ConsenSys 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. | ||
*/ | ||
package tech.pegasys.pantheon.ethereum.permissioning; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain; | ||
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive; | ||
|
||
import tech.pegasys.pantheon.config.GenesisConfigFile; | ||
import tech.pegasys.pantheon.ethereum.chain.GenesisState; | ||
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; | ||
import tech.pegasys.pantheon.ethereum.core.Address; | ||
import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; | ||
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; | ||
import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; | ||
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; | ||
import tech.pegasys.pantheon.util.enode.EnodeURL; | ||
|
||
import java.io.IOException; | ||
|
||
import com.google.common.io.Resources; | ||
import org.junit.Test; | ||
|
||
public class SmartContractPermissioningControllerTest { | ||
|
||
private SmartContractPermissioningController setupController( | ||
final String resourceName, final String contractAddressString) throws IOException { | ||
final ProtocolSchedule<Void> protocolSchedule = MainnetProtocolSchedule.create(); | ||
|
||
final String emptyContractFile = Resources.toString(Resources.getResource(resourceName), UTF_8); | ||
final GenesisState genesisState = | ||
GenesisState.fromConfig(GenesisConfigFile.fromConfig(emptyContractFile), protocolSchedule); | ||
|
||
final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock()); | ||
final WorldStateArchive worldArchive = createInMemoryWorldStateArchive(); | ||
|
||
genesisState.writeStateTo(worldArchive.getMutable()); | ||
|
||
final TransactionSimulator ts = | ||
new TransactionSimulator(blockchain, worldArchive, protocolSchedule); | ||
final Address contractAddress = Address.fromHexString(contractAddressString); | ||
|
||
return new SmartContractPermissioningController(contractAddress, ts); | ||
} | ||
|
||
@Test | ||
public void testIpv4Included() throws IOException { | ||
final SmartContractPermissioningController controller = | ||
setupController( | ||
"SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", | ||
"0x0000000000000000000000000000000000001234"); | ||
|
||
assertThat( | ||
controller.isPermitted( | ||
new EnodeURL( | ||
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.1:30303"), | ||
new EnodeURL( | ||
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.1:30304"))) | ||
.isTrue(); | ||
} | ||
|
||
@Test | ||
public void testIpv4DestinationMissing() throws IOException { | ||
final SmartContractPermissioningController controller = | ||
setupController( | ||
"SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", | ||
"0x0000000000000000000000000000000000001234"); | ||
|
||
assertThat( | ||
controller.isPermitted( | ||
new EnodeURL( | ||
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.1:30303"), | ||
new EnodeURL( | ||
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.1:30305"))) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
public void testIpv4SourceMissing() throws IOException { | ||
final SmartContractPermissioningController controller = | ||
setupController( | ||
"SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", | ||
"0x0000000000000000000000000000000000001234"); | ||
|
||
assertThat( | ||
controller.isPermitted( | ||
new EnodeURL( | ||
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.1:30302"), | ||
new EnodeURL( | ||
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.1:30304"))) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
public void testIpv6Included() throws IOException { | ||
final SmartContractPermissioningController controller = | ||
setupController( | ||
"SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", | ||
"0x0000000000000000000000000000000000001234"); | ||
|
||
assertThat( | ||
controller.isPermitted( | ||
new EnodeURL( | ||
"enode://1234000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ab61@[1:2:3:4:5:6:7:8]:30303"), | ||
new EnodeURL( | ||
"enode://1234000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ab62@[1:2:3:4:5:6:7:8]:30304"))) | ||
.isTrue(); | ||
} | ||
|
||
@Test | ||
public void testIpv6SourceMissing() throws IOException { | ||
final SmartContractPermissioningController controller = | ||
setupController( | ||
"SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", | ||
"0x0000000000000000000000000000000000001234"); | ||
|
||
assertThat( | ||
controller.isPermitted( | ||
new EnodeURL( | ||
"enode://1234000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ab63@[1:2:3:4:5:6:7:8]:30303"), | ||
new EnodeURL( | ||
"enode://1234000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ab62@[1:2:3:4:5:6:7:8]:30304"))) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
public void testIpv6DestinationMissing() throws IOException { | ||
final SmartContractPermissioningController controller = | ||
setupController( | ||
"SmartContractPermissioningControllerTest/preseededSmartPermissioning.json", | ||
"0x0000000000000000000000000000000000001234"); | ||
|
||
assertThat( | ||
controller.isPermitted( | ||
new EnodeURL( | ||
"enode://1234000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ab61@[1:2:3:4:5:6:7:8]:30303"), | ||
new EnodeURL( | ||
"enode://1234000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ab63@[1:2:3:4:5:6:7:8]:30304"))) | ||
.isFalse(); | ||
} | ||
} |
Oops, something went wrong.