Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TestModels): Resource #103

Merged
merged 47 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4a5d2c2
test(resource): init testing of resource shim in C#
texastony Jan 30, 2023
a74aaa9
fix(resources): polymorph's smithydotnet does not handle bigInit or b…
texastony Jan 30, 2023
ee3e4b0
feat: init Makefile for test
texastony Jan 31, 2023
df4a884
chore: ignore JetBrains
texastony Jan 31, 2023
e1b2cc3
fix: resources.smithy
texastony Jan 31, 2023
f144f7d
fix: smithy-polymorph call's Model must be a directory
texastony Jan 31, 2023
93d66b6
chore: ignore generate types files
texastony Jan 31, 2023
915e470
chore: ignore generated dafny in tests
texastony Jan 31, 2023
717ccd2
fix: Polymorph smithy-dafny MUST write to Model
texastony Jan 31, 2023
19ff9bf
Merge branch 'main-1.x' into tony/test-resources
texastony Jan 31, 2023
9c0aee2
Merge branch 'main-1.x' into tony/test-resources
texastony Jan 31, 2023
d7518c1
Merge branch 'main-1.x' into tony/test-resources
texastony Feb 1, 2023
fa0c8d6
fix: Service needs a concrete error
texastony Feb 2, 2023
f495b3d
feat: Simple implementaiton
texastony Feb 2, 2023
1af036c
Merge branch 'main-1.x' into tony/test-resources
texastony Feb 2, 2023
4fd0bfc
feat: Simple Resource Service
texastony Feb 2, 2023
e9060c4
refactor: remove un-needed post-conditions
texastony Feb 2, 2023
6fa9de7
feat: compile impl to C#
texastony Feb 2, 2023
f073948
wip: test the implementation
texastony Feb 3, 2023
4e7cf00
wip: transpile_net_test still fails w/ very simple test
texastony Feb 3, 2023
9cd0b43
Merge branch 'main-1.x' of github.com:awslabs/polymorph into tony/tes…
texastony Feb 3, 2023
813dc9e
wip: transpile_net_test still fails w/ very simple test
texastony Feb 3, 2023
77b53ac
wip: transpile_net_test still fails w/ very simple test
texastony Feb 3, 2023
ba5b980
wip: trans_net_test still fails w/o Independent Config
texastony Feb 3, 2023
ca735c2
debug: force check in Types
texastony Feb 3, 2023
d42449f
revert: debug: force check in Types
texastony Feb 3, 2023
e64a588
debug: force check in Types
texastony Feb 3, 2023
40ecc9a
fix: work around issue in f073948
texastony Feb 3, 2023
47d5e44
test: restore complete service testing
texastony Feb 3, 2023
aa765c8
fix: remove Model/...Types.dfy
texastony Feb 3, 2023
30fe621
fix(csproj): include Extern in test
texastony Feb 3, 2023
21db487
wip: Test Wrapped Service
texastony Feb 3, 2023
306cbaf
issue: broken wrapped C# code
texastony Feb 3, 2023
fa49b2b
debug: try forcing non-NativeWrapper conversion
texastony Feb 3, 2023
70beb46
debug: try forcing NativeWrapper conversion
texastony Feb 4, 2023
09aafe2
issue: WrappedCodegen's NativeWrapper assumes Exception name
texastony Feb 4, 2023
bbe673d
fix: issue in 09aafe2
texastony Feb 4, 2023
dc44957
style: reformat C# for better comparison
texastony Feb 4, 2023
6fdb22b
style: run dotnet format
texastony Feb 6, 2023
19493c3
feat(TestModels): Resource
texastony Feb 13, 2023
6e4d07f
fix(smithy-dotnet): Local Service Wrapper
texastony Feb 13, 2023
565ac6c
Merge branch 'main-1.x' into tony/test-resources
texastony Feb 13, 2023
055a1ed
style(TestModels): Resource
texastony Feb 13, 2023
be67a87
refactor(TestModels): Resource
texastony Feb 13, 2023
343c96f
Merge branch 'main-1.x' into tony/test-resources
texastony Feb 23, 2023
fe10052
ci: add TestModel/Resource to CI
texastony Feb 23, 2023
705ccb6
feat: README for TestModel/Resource
texastony Feb 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions TestModels/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# .NET Test Results
**/TestResults

# Dafny Generated .NET
**/ImplementationFromDafny.cs
**/TestsFromDafny.cs

# .NET Artifacts
**/bin
**/obj

# JetBrains
**/.idea/

# Generated Dafny
**/*Types.dfy
**/*TypesWrapped.dfy
23 changes: 23 additions & 0 deletions TestModels/resources/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

CORES=2
PWD := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))

polymorph_dafny:
gradle -p ../../smithy-polymorph run --args="\
--output-dafny \
--include-dafny $(PWD)/../dafny-dependencies/StandardLibrary/src/Index.dfy \
--model $(PWD)/Model \
--dependent-model $(PWD)/../dafny-dependencies/Model \
--namespace simple.resources";
gradle -p ../../smithy-polymorph run --args="\
--output-dafny \
--output-local-service-test $(PWD)/Model \
--include-dafny $(PWD)/../dafny-dependencies/StandardLibrary/src/Index.dfy \
--model $(PWD)/Model \
--dependent-model $(PWD)/../dafny-dependencies/Model \
--namespace simple.resources";

clean:
rm $(PWD)/Model/*.dfy
81 changes: 81 additions & 0 deletions TestModels/resources/Model/resources.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
namespace simple.resources

@aws.polymorph#localService(
sdkId: "SimpleResources",
config: SimpleResourcesConfig,
)
service SimpleResources {
version: "2021-11-01",
resources: [],
operations: [ GetResources ],
errors: [ SimpleResourceException ],
}

structure SimpleResourcesConfig {}

// This operation MUST
// return the values given in the Resources.
// The internal config MUST somehow differ,
// and this additional information MUST be returned.
operation GetResources {
input: GetResourcesInput,
output: GetResourcesOutput,
}

structure GetResourcesInput {
value: String
}

structure GetResourcesOutput {
@required
output: SimpleResourceReference
}

@aws.polymorph#reference(resource: SimpleResource)
structure SimpleResourceReference {}

resource SimpleResource {
operations: [ GetResourceData ]
}

operation GetResourceData {
input: GetResourceDataInput,
output: GetResourceDataOutput,
}

structure GetResourceDataInput {
blobValue: Blob,
booleanValue: Boolean,
stringValue: String,
// byteValue: Byte,
// shortValue: Short,
integerValue: Integer,
longValue: Long,
// floatValue: Float,
// doubleValue: Double,
// bigIntegerValue: BigInteger,
// bigDecimalValue: BigDecimal,
// timestampValue: Timestamp,
}

structure GetResourceDataOutput {
blobValue: Blob,
booleanValue: Boolean,
stringValue: String,
// byteValue: Byte,
// shortValue: Short,
integerValue: Integer,
longValue: Long,
// floatValue: Float,
// doubleValue: Double,
// bigIntegerValue: BigInteger,
// bigDecimalValue: BigDecimal,
// timestampValue: Timestamp,
}

@error("client")
structure SimpleResourceException {
@required
message: String,
}

23 changes: 23 additions & 0 deletions TestModels/resources/src/Config.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

include "../Model/SimpleResourcesTypes.dfy"

module Config {
import opened StandardLibrary
import Types = SimpleResourcesTypes

datatype Config = Config(
nameonly name: string,
nameonly modified: bool := false
texastony marked this conversation as resolved.
Show resolved Hide resolved
)

predicate method ValidInternalConfig?(config: Config)
{
&& |config.name| > 0
}

function ModifiesInternalConfig(config: Config): set<object>
{{}}

}
75 changes: 75 additions & 0 deletions TestModels/resources/src/SimpleResource.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

include "../Model/SimpleResourcesTypes.dfy"
include "./Config.dfy"

module SimpleResource {
import opened StandardLibrary
import opened Wrappers
import opened Config
import Types = SimpleResourcesTypes

class SimpleResource extends Types.ISimpleResource
{
const config: Config

predicate ValidState()
ensures ValidState() ==> History in Modifies
{
&& History in Modifies
&& ModifiesInternalConfig(config) <= Modifies
&& History !in ModifiesInternalConfig(config)
&& ValidInternalConfig?(config)
}

const value: string

constructor (
value: string,
config: Config
)
requires ValidInternalConfig?(config)
ensures this.value == value
ensures this.config == config
ensures ValidState() && fresh(History) && fresh(Modifies - ModifiesInternalConfig(config))
{
this.value := value;
this.config := config;

History := new Types.ISimpleResourceCallHistory();
Modifies := { History } + ModifiesInternalConfig(config);
}

predicate GetResourceDataEnsuresPublicly(
input: Types.GetResourceDataInput,
output: Result<Types.GetResourceDataOutput, Types.Error>
) {true}

method GetResourceData'(
input: Types.GetResourceDataInput
) returns (
output: Result<Types.GetResourceDataOutput, Types.Error>
)
requires ValidState()
modifies Modifies - {History}
decreases Modifies - {History}
ensures && ValidState()
ensures GetResourceDataEnsuresPublicly(input, output)
ensures unchanged(History)
{
var rtnString: string := if input.stringValue.Some? then
this.config.name + " " + input.stringValue.value
else
this.config.name;
var rtn: Types.GetResourceDataOutput := Types.GetResourceDataOutput(
blobValue := input.blobValue,
booleanValue := input.booleanValue,
stringValue := Option.Some(rtnString),
integerValue := input.integerValue,
longValue := input.longValue
);
return Success(rtn);
}
}
}
44 changes: 44 additions & 0 deletions TestModels/resources/src/SimpleResourcesOperations.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

include "../Model/SimpleResourcesTypes.dfy"
include "./Config.dfy"
include "./SimpleResource.dfy"

module SimpleResourcesOperations refines AbstractSimpleResourcesOperations {
import Config
import SimpleResource

type InternalConfig = Config.Config

predicate GetResourcesEnsuresPublicly(
input: GetResourcesInput,
output: Result<GetResourcesOutput, Error>
) {true}

method GetResources(
config: InternalConfig,
input: GetResourcesInput
) returns (
output: Result<GetResourcesOutput, Error>
texastony marked this conversation as resolved.
Show resolved Hide resolved
)
{
:- Need(Config.ValidInternalConfig?(config),
Types.SimpleResourceException(
message := "Simple Resource Client has become invalid")
);
texastony marked this conversation as resolved.
Show resolved Hide resolved
:- Need(input.value.Some?,
Types.SimpleResourceException(
message := "Input Value MUST be set")
);
var resource := new SimpleResource.SimpleResource(
input.value.value,
config
texastony marked this conversation as resolved.
Show resolved Hide resolved
);
var result: GetResourcesOutput := GetResourcesOutput(
output := resource
);
return Success(result);
}

}