mirror of
https://github.com/corda/corda.git
synced 2025-06-24 02:04:12 +00:00
Improved unit tests.
Cleaned up project structure a bit.
This commit is contained in:
80
contracts/isolated/build.gradle
Normal file
80
contracts/isolated/build.gradle
Normal file
@ -0,0 +1,80 @@
|
||||
import com.google.common.io.ByteStreams
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.StandardCopyOption
|
||||
import java.nio.file.attribute.FileTime
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "com.google.guava:guava:19.0"
|
||||
}
|
||||
}
|
||||
|
||||
// Custom Gradle plugin that attempts to make the resulting jar file deterministic.
|
||||
// Ie. same contract definition should result when compiled in same jar file.
|
||||
// This is done by removing date time stamps from the files inside the jar.
|
||||
class CanonicalizerPlugin implements Plugin<Project> {
|
||||
void apply(Project project) {
|
||||
|
||||
project.getTasks().getByName('jar').doLast() {
|
||||
|
||||
def zipPath = (String) project.jar.archivePath
|
||||
def destPath = Files.createTempFile("processzip", null)
|
||||
|
||||
def zeroTime = FileTime.fromMillis(0)
|
||||
|
||||
def input = new ZipFile(zipPath)
|
||||
def entries = input.entries().toList().sort { it.name }
|
||||
|
||||
def output = new ZipOutputStream(new FileOutputStream(destPath.toFile()))
|
||||
output.setMethod(ZipOutputStream.DEFLATED)
|
||||
|
||||
entries.each {
|
||||
def newEntry = new ZipEntry( it.name )
|
||||
|
||||
newEntry.setLastModifiedTime(zeroTime)
|
||||
newEntry.setCreationTime(zeroTime)
|
||||
newEntry.compressedSize = -1
|
||||
newEntry.size = it.size
|
||||
newEntry.crc = it.crc
|
||||
|
||||
output.putNextEntry(newEntry)
|
||||
|
||||
ByteStreams.copy(input.getInputStream(it), output)
|
||||
|
||||
output.closeEntry()
|
||||
}
|
||||
output.close()
|
||||
input.close()
|
||||
|
||||
Files.move(destPath, Paths.get(zipPath), StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
apply plugin: CanonicalizerPlugin
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
maven {
|
||||
url 'http://oss.sonatype.org/content/repositories/snapshots'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':core')
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2015 Distributed Ledger Group LLC. Distributed as Licensed Company IP to DLG Group Members
|
||||
* pursuant to the August 7, 2015 Advisory Services Agreement and subject to the Company IP License terms
|
||||
* set forth therein.
|
||||
*
|
||||
* All other rights reserved.
|
||||
*/
|
||||
|
||||
package contracts.isolated
|
||||
|
||||
import core.Contract
|
||||
import core.ContractState
|
||||
import core.TransactionForVerification
|
||||
import core.crypto.SecureHash
|
||||
|
||||
// The dummy contract doesn't do anything useful. It exists for testing purposes.
|
||||
|
||||
val ANOTHER_DUMMY_PROGRAM_ID = SecureHash.sha256("dummy")
|
||||
|
||||
class AnotherDummyContract : Contract {
|
||||
class State : ContractState {
|
||||
override val programRef: SecureHash = ANOTHER_DUMMY_PROGRAM_ID
|
||||
}
|
||||
|
||||
override fun verify(tx: TransactionForVerification) {
|
||||
// Always accepts.
|
||||
}
|
||||
|
||||
// The "empty contract"
|
||||
override val legalContractReference: SecureHash = SecureHash.sha256("https://anotherdummy.org")
|
||||
}
|
Reference in New Issue
Block a user